# Triangles java problem (basic help)

• 10-31-2009, 07:01 PM
Triangles java problem (basic help)
Hello basically i am wondering how if the triangle isnt valid to get the program to terminate and not countinue to work out what type of triangle it is.

It looks a bit stupid when i shows up
"this is not a valid triangle"
"This is a scalene triangle"

Program so far:- (this program compiles and works fine i just want to figure out how to do the above and how to modify it)

Code:

```public class        Triangles4 {     public static void main(String[] args)             { int side_a = getScannerInput.anInt("Please enter a positive integer to represent side a. "); int side_b = getScannerInput.anInt("Please enter a positive integer to represent side b. "); int side_c = getScannerInput.anInt("Please enter a positive integer to represent side c. ");         System.out.println ("The values you entered were " + side_a + "," + side_b + "," + side_c + ".");       {                   if((side_a+side_b>side_c)&&(side_a+side_c>side_b)&&(side_c+side_b>side_a))                   System.out.println ("The values," + side_a + "," + side_b + "," + side_c + " could form the sides of a triangle.");                                     else                   System.out.println ("The values,"+ side_a + "," + side_b + "," + side_c + " could NOT form the sides of a triangle.");}                                                             if(side_a==side_b&&side_b==side_c&&side_c==side_a)                       System.out.println ("This would form and Equilateral Triangle");                                                     else if ((side_a==side_b&&side_a!=side_c)||(side_b==side_c&&side_b!=side_a)||(side_c==side_a&&side_c!=side_b))                                       System.out.println ("This would form an Isosceles Triangle");                                                             else if ((side_a!=side_b)&&(side_b!=side_c)&&(side_c!=side_a))                                       System.out.println ("This would form an Scalene Triangle");                                                                                                                   } }```
Thanks
p.s im new to java as in only been using it for 2 weeks.
• 10-31-2009, 07:35 PM
hardwired
if the triangle isnt valid
How would you define this? What would make a triangle invalid?
How about: if the sum of any two sides is less than the third side?
• 10-31-2009, 07:38 PM
r035198x
Just use

Code:

`System.exit(0);`
to stop the program.
• 10-31-2009, 07:44 PM
Quote:

Originally Posted by hardwired
if the triangle isnt valid
How would you define this? What would make a triangle invalid?
How about: if the sum of any two sides is less than the third side?

Yes that is the theory i am currently using.

System.exit(0); Wont work due to the fact that if the triangle is valid i DO NOT want the program to terminiate i would it to continue and tell me what type of triangle it is.
• 10-31-2009, 07:52 PM
r035198x
Code:

```else { System.out.println ("The values,"+ side_a + "," + side_b + "," + side_c + " could NOT form the sides of a triangle."); System.exit(0); }```
P.S Format your code and use code tags when posting code.
• 10-31-2009, 07:58 PM
Quote:

Originally Posted by r035198x
Code:

```else { System.out.println ("The values,"+ side_a + "," + side_b + "," + side_c + " could NOT form the sides of a triangle."); System.exit(0); }```
P.S Format your code and use code tags when posting code.

Thanks very much was trying brackets around the full "if" statement and not the else.
And sorry about posting inccorectly i will know for again.
Thanks