# Help with if else statements

• 09-23-2010, 09:42 PM
np2392
Help with if else statements
Hi, I'm new to java. I'm taking a class at my university and my homework is to design a program which will calculate the area of a triangle using Heron's Formula. My instructor also wanted us to use an if else statement so if it is an invalid triangle the program would let the user know.

I'm not sure what's wrong with my program. I use eclipse, and it tells me "Syntax error on token "else", delete this token"

Any help is appreciated.

Code:

```import java.util.Scanner; public class HerosFormula {     public static void main(String[]args)     {         System.out.println("Enter the three sides of the triangle to caluclate its area.");                 int n1, n2, n3, n4;         double n5;                 Scanner keyboard = new Scanner(System.in);         n1 = keyboard.nextInt();         n2 = keyboard.nextInt();         n3 = keyboard.nextInt();                 n4 = (n1 + n2 + n3)/2;                 n5 = Math.sqrt(n4 * (n4-n1) * (n4-n2) * (n4-n3));                 if ((n1>n2+n3) || (n2>n1+n3) || (n3>n1+n2) || (n1<n2-n3) || (n1<n3-n2) || (n2<n1-n3) || (n2<n3-n1) || (n3<n1-n2) || (n3<n2-n1));             System.out.println("Invalid triangle");         else                System.out.println("The area of the the triangle is:");             System.out.println(n5);             } }```
• 09-23-2010, 09:47 PM
Norm
You have a ; at the end of the if statement that ends the if statement. The next statements are not part of that if
• 09-24-2010, 01:25 AM
np2392
Thank you!