TRENDING NEWS

POPULAR NEWS

Help With Pythagorean Triangles In Java

Pythagorean Triples Help 75 85...?

"The given lengths are two sides of a right triangle. All three side lengths of the triangle are integers and together form a Pythagorean triple. Find the length of the the third side and tell whether it is a leg or the hypotenuse. "

PLEASE HELPP MEE

75 and 85

Is 1,√3, 2 a pythagorean triple? If it is show why.?

Technically, 1, √3, 2 is not a pythagorean triple, because a pythagorean triple consists of three integers such that

a^2 + b^2 = c^2

and √3 is not an integer.
However it is true that 1, √3, 2 would be the sides of a right angled triangle, since

1^2 + (√3)^2 = 2^2
1 + 3 = 4
Which is the pythagorean theorem. Remember that all pythagorean triples are solutions to the pythagorean theorem, but they only consist of integers.

Help with pythagorean triangles in JAVA?

I got a question to ---
Write a Java program that will print out the length of the side of all triangles that are a
Pythagorean Triple Triangle. The lengths of the sides must satisfy the following to be considered
such a triangle: The sum of the squares of two of the sides must equal the square of the length
of the hypotenuse. Your program should print out all triangles that satisfy this condition with
sides no larger than 200.
For example, the triangle with sides 3,4 and 5 is considered a Pythagorean Triple Triangle
because 3^2 + 4^2 = 5^2 (9 + 16 =25).

I basically said in the answer that
int n=1;
while (n<200)
{

if(n%3==0&&n%4==0&&n%5==0)
{
System.out.println(n+ "");


but it just crased my programme
im thinking that if its a mulitple of 3,4,5 it has to be a pythagorean triangle??
if anyone could fix that bit of code it would be very appreciated !:)

How do you code the Pythagorean theorem in Java?

Good lord. Doesn’t anyone do a google search anymore?Java Code for Pythagoras Theorem

Pythagorean Theorem?

Don't appreciate your comments, blonde dancer. I have ADD, thanks alot. Anyway thanks for all the help, I can't possibly choose a best answer so I will let the puclic decide.

How would the Pythagorean Theorem look if c = sqrt (a^2 + b^2)?

Hey allah mein hoon tera banda hoon mujhe hidayat taki mainbhi is duniya main kuch achha kar paun mera bhi naam ho apna samajh main ourappne paribaar main bhi taki main a jaanlu k tu bhi is duniya mere liyen Hey allah meregunhah hoka map pharma hey hum insanoko jeene k jaariya de taaki aapke ibadat kar sake hey mere maulahey mere parbardikar allah allah hoonWrite byarove ali khan

How would you find all the Pythagorean triplets in an array of n numbers?

There is a neat little trick which can be used to solve the problem worst case time [math]O(n^2)[/math].Lets assume that the given array is [math]A[/math]. Create another array [math]S[/math], which contains the square of all the numbers in [math]A[/math]. Now, sort the array [math]S[/math] in ascending order. We would consider every element of [math]S[/math], say [math]S_i[/math] as the hypotenuse squared and try to find two other elements in [math]S[/math], say [math]S_j, S_k[/math], such that [math]S_i = S_j + S_k, i \neq j, i \neq k, j \neq k[/math].To find the numbers [math]S_j[/math] and [math]S_k[/math], start with [math]j = 0[/math] and [math]k = n - 1[/math]. If [math]S_j + S_k > S_i[/math], then we need to decrease the sum [math]S_j + S_k[/math]. This can be done by decreasing [math]k[/math] to [math]n - 2[/math]. On the other hand if [math]S_j + S_k < S_i[/math] then we need to increase the sum [math]S_j + S_k[/math]. This can be done by increasing [math]j[/math] to [math]1[/math]. If [math]S_j + S_k = S_i[/math], then we have found a triplet. While programming, it should be ensured that [math]j[/math] and [math]k[/math] are increased and decreased respectively if they equal to [math]i[/math] at any point. Also, it should be ensured that [math]j < k[/math]. For a given [math]i[/math], this can run in [math]O(n)[/math] time, so the total time complexity is [math]O(n^2)[/math].EDIT, Adding Mark Gritter's comment:We don't need to start with [math]k = n - 1[/math] as, for any given triplet [math]j < i[/math] and [math]k < i[/math]. So, we can start with [math]k = i - 1[/math]. This also avoids taking care of the conditions [math]j \neq i[/math] and [math]k \neq i[/math]. Also, if for [math]S_i[/math], a triplet is found then increase [math]j[/math] to [math]j + 1[/math]and decrease [math]k[/math] to [math]k - 1[/math] and repeat the process. The iteration stops when [math]j >= k[/math].

Ive struggled with the pythagoras theorem for a long time- can anyone help me please?

Pythagoras Theorem asserts that for a right triangle with short sides of length a and b and long side of length c
a2 + b2 = c2

or c2-a2 = b2

here is a link with all the necessary thing you have to know about this theorem . I hope it helps , just read it carefully and everything is going to be fine :)

Anyone good with triple nested loops in java?

I am stuck on this java assignment where I am supposed to use triple nested loops in the code.

Its not supposed to get any input from a user and its really throwing me off. Could someone help me with this please??

This is what my assignment says:
A right triangle can have side whose lengths are all positive integers. The set of these integer values of lengths of sides of such a triangle is called a Pythagorean Triple. The lengths of the three sides must satisfy the relationship that the sum of the squares of two of the sides (called legs) must equal the square of the length of the hypotenuse (longest side). Write a Java application to find all Pythagorean Triples for side1, side2 and the hypotenuse, each no larger than 200. Use a triple-nested for loop that tries all possibilities. This type of problem solution is called a “brute force” type of solution.
There should be no input to the problem solution, and the output should be the specified set of Pythagorean Triples in a reasonably readable form.

How do I type the Pythagoras method using Java (source code)?

public class PythagoreanTheorem
{
private Double a,b,c;

public Double getA() { return a; }
public Double getB() { return b; }
public Double getC() { return c; }

public PythagoreanTheorem( Double a, Double b, Double c )
{
this.a = a;
this.b = b;
this.c = c;

validate();
}

private void validate()
{
if ( a == null && b == null ||
b == null && c == null ||
a == null && c == null )
{
throw new NullPointerException("Two values must be provided.");
}
else if ( a != null && b != null && c != null )
{
if ( c != Math.sqrt( a*a + b*b ))
{
throw new IllegalArgumentException("Values given cannot form a right triangle.");
}
}
}

private void solveA()
{
a = Math.sqrt(c*c - b*b);
}

private void solveB()
{
b = Math.sqrt(c*c - a*a);
}

private void solveC()
{
c = Math.sqrt(a * a + b * b);
}

public void solve()
{
if ( a == null )
solveA();
else if ( b == null )
solveB();
else
solveC();
}

@Override
public String toString()
{
StringBuilder sb = new StringBuilder();

sb.append("A = ");
if (a == null)
sb.append("null");
else
sb.append(a);

sb.append(", B = ");
if (b == null)
sb.append("null");
else
sb.append(b);

sb.append(", C = ");
if (c == null)
sb.append("null");
else
sb.append(c);

return sb.toString();
}

public static void main(String[] args)
{
PythagoreanTheorem pt = new PythagoreanTheorem( 3.0, null, 5.0 );
pt.solve();
System.out.println(pt.toString());
}
}

TRENDING NEWS