# Thread: Is it a right triangle? (Code help)

1. Member
Join Date
Oct 2008
Posts
4
Rep Power
0

## Is it a right triangle? (Code help)

Hi! My task is to create a program that takes the input of three sides of a triangle and displays a message of whether or not it is a right triangle.

Here is what I have so far...
------------------------------
import java.util.Scanner;
public class triangle {

public static void main(String[] args) {

double sidea;
double sideb;
double sidec;

Scanner in = new Scanner(System.in);
System.out.println("Enter the 3 sides of the triangle: ");

sidea = in.nextDouble();
sideb = in.nextDouble();
sidec = in.nextDouble();

//if it is a right triangle
if (((sidea * sidea) + (sideb * sideb)) == (sidec * sidec));
if (((sidea * sidea) + (sidec * sidec)) == (sideb * sideb));
if (((sidec * sidec) + (sideb * sideb)) == (sidea * sidea));

}

}

------------------------------------------------------

I need help making an else statement that says (if all that "if" statement above is NOT true, then it is NOT a right triangle)!

Thanks!!

2. Java Code:
```if (A | B | C) {
true;
}else{
false;
}```

3. Member
Join Date
Oct 2008
Posts
4
Rep Power
0
Keeps saying that line 29 (true;) and line 31 (false;) are not statements : \

4. Member
Join Date
Oct 2008
Posts
4
Rep Power
0
sorry those smileys were supposed to be semicolons?- Was I supposed to put that code in underneath my System.out.print?
Last edited by TheApostle; 10-07-2008 at 07:11 PM.

5. If you get compile errors, copy FULL text of the error messages here.
I don't know where line 29 and 31 are.

The code I posted was not java. It was just to show you how to use OR with an if statement.

6. Senior Member
Join Date
Aug 2008
Location
Stockholm, Sweden
Posts
119
Rep Power
0
Norm gave you one way to solve this. Read up on how if-else works. I'd do it like this:

Java Code:
```if (something) {
// code
} else if (something else) {
// code
} else {
// code
}```
Or you can set "answer" to "not a right triangle" and just change it if it is, like you do now. Or you can just a boolean. There are many ways to do this.

7. Member
Join Date
Oct 2008
Posts
4
Rep Power
0
Ok sorry about being stupid there for a second. I understand what you posted now and I implemented it into my code.
-----------

}else{

System.out.print("Not a right triangle");
-----------

Just one problem is that it is saying that it cannot apply the "OR" (|) operator to a string. (the variable "answer" is a string)

8. Check this ...
java.sun.com/docs/books/tutorial/java/nutsandbolts/if.html

CJSL

Where you have "answer" must evaluate to either true or false.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•