+ 1
CODING CLUB: CHALLENGE 4
Write a program that asks the user to enter 3 numbers, each representing the length of a triangle side. Determine if the side lengths make a valid triangle (if not sure look up the definition of a valid triangle). In addition, determine if the side lengths make a pythagorean(perfect) triangle (i.e. a^2 + b^2 = c^2). Example - input: 3, 4, 2. output - True, false //meaning true for a valid triangle and false for a perfect triangle
7 ответов
+ 1
yup looks good. although instead of having all those if statements in the pyTheory method, i would make an array of the sides so that you can sort them, and would only have to do a^2 + b^2 = c^2, once
0
I have completed the first part of this, now I just need to add a method which checks of it is a pythagorean
0
I can't get my PyTheory() method to work. it always returns false, if anyone has any ides. I haven't added the class with Main() as it just makes a triangle instance and calls message();
http://pastebin.com/dZmYbhHi
0
I have fixed the problem. I realised that I'm asking for the square root and not squaring the numbers. so I've changed the IF statements to if((side1 * side1) + (side2 * side2) == (side3 * side3); {
print code
}
0
I'll try and update it. I added it to another forum and they've suggested some other things too. will see how things go.
0
can i see what they suggested. im also beginner and wanna learn how to improve my code
0
they suggest a few things and the thread gets a bit side tracked. but there is some useful info there. https://coderanch.com/t/668786/java/java/user-integers-find-triangle