Can't figure out why my Else statement won't work
Hello all,
I have just started learning to program and am driving myself crazy trying to figure out why a program I wrote won't print (lines 48-50 below). It compiles and runs, it just doesn't print line 49.
The point of the program is to determine if 3 numbers input by a user could represent the sides of a triangle. The code I came up with works if the numbers could be a triangle (it prints "The numbers you entered could represent the sides of a triangle.") but it won't print a message if it's not a triangle. I tried surrounding the IF and ELSE statements with various arrangements of brackets with no luck. I'm sure it's something obvious that I'm overlooking but i don't know what it is. Anyone see where I'm going wrong?
Thanks!
PS- I don't know how to include the box with the scroll bar in my post. Sorry!
8 import java.util.Scanner;//import Scanner class so we can get user input from keyboard
9 public class Triangle //name of program
10 {
11 //Main method begins execution of Java program
12 public static void main( String[] args )
13 {
14 //Scanner lets us take in information typed in by keyboard
15 Scanner keyboard = new Scanner (System.in);
16
17 double number1;//first number to compare
18 double number2;//second number to compare
19 double number3;//third number to comapre
20
21 //Prompt user to enter number
22 System.out.println(" Please enter a number greater than 0.");
23 //Read number
24 number1 = keyboard.nextDouble();
25
26 //Prompt user to enter number
27 System.out.println(" Please enter a second number greater than 0.");
28 //Read number
29 number2 = keyboard.nextDouble();
30
31 //Prompt user to enter number
32 System.out.println(" Please enter a third number greater than 0.");
33 //Read number
34 number3 = keyboard.nextDouble();
35
36 //Compare numbers. If they meet the requirements print to screen
37 //that it could be a triangle.
38
39 if ( (number1 + number2) >= number3 )
40
41 if ( (number2 + number3) >= number1 )
42
43 if ( (number3 + number1) >= number2)
44 System.out.println( "The numbers you entered could represent the sides of a triangle.");
45
46 //if numbers don't satisfy above requirement print to screen
47 //that the numbers can not represent a triangle.
48 else
49 System.out.println("The numbers you entered can not represent the sides of a triangle.");
50
51
52 }//end main method
53 }//end class