# Thread: Help with if else statements

1. Member Join Date
Sep 2010
Posts
5
Rep Power
0

## 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.

Java 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);

}
}```  Reply With Quote

2. ## You have a ; at the end of the if statement that ends the if statement. The next statements are not part of that if  Reply With Quote

3. Member Join Date
Sep 2010
Posts
5
Rep Power
0

## Thank you!  Reply With Quote

#### Posting Permissions

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