Problems with Java Triangle Type Program -


import java.util.scanner;  public class labassignment4 {     public static void main(string[] args){         scanner user = new scanner(system.in);         //variables         double a, b, c;          system.out.println("enter longest side: ");         = user.nextdouble();         system.out.println("enter second side: ");         b = user.nextdouble();         system.out.println("enter third side: ");         c = user.nextdouble();         //help fix code compute triangle type correctly...                  if (a==b&&b==c)                 {                     system.out.println("equilateral triangle");                 }                  else if (a==b && b==c);                     {                         system.out.println("isoceles triangle");                     }                     if (!((a == b) && (a == c) && (b == c)));                      {                     system.out.println("scalene triangle");                     }                     if (((a + b) >= (c)) ||((a + b) >= (b)) ||((b +c) >= (a)));                     {                         system.out.println("not triangle");                     }              }      } 

help correct formula compute correct triangle type....any appreciated. need modifying code , seems keeps giving me error returning more 1 result. result receive values equal isoceles, scalene, , not triangle values @ once.

a problem have semicolon after else statement:

 else if (a==b && b==c);//<-- semicolon here 

thus print `"isoceles triangle"

also, have semicolons after next 2 if statements:

if (!((a == b) && (a == c) && (b == c))); //<-- semicolon here {    system.out.println("scalene triangle"); } if (((a + b) >= (c)) ||((a + b) >= (b)) ||((b +c) >= (a))); //<-- semicolon here {    system.out.println("not triangle"); } 

these cause program print "scalene triangle" , "not triangle" regardless of whether or not test conditions in if statement true/false.

the fix simple: remove semicolons!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -