# Triangle Sides program

• 10-06-2008, 12:13 AM
jamesov89
Triangle Sides program
Hey fellow programmers. I was wondering if you could help me out with an assignment. I don't want it purely done fro em but if you could point out the error I have made then I would be very grateful.

The assignment is to ask 3 numbers that are the sides of a triangle. For each set of numbers, print what type of triangle it creates.

{code}
import java.util.Scanner;
public class lab5 {

public static void main(String[] args) {

double sidea;
double sideb;
double sidec;

Scanner in = new Scanner(System.in);
System.out.println("Enter the 3 sides of a triangle: ");

sidea = in.nextDouble();
sideb = in.nextDouble();
sidec = in.nextDouble();

System.out.println("Sides " + sidea + sideb +sidec);

if (((sidea * sidea) + (sideb * sideb)) == (sidec * sidec));
answer = "right triangle";
if (((sidea * sidea) + (sidec * sidec)) == (sideb * sideb));
answer = "right triangle";
if (((sidec * sidec) + (sideb * sideb)) == (sidea * sidea));
answer = "right triangle";

//right triangle

if (sidea == sideb == sidec);
answer = "equilateral triangle";

//equilateral triangle

if ((sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec));

if (sidea = 0.0 || sideb = 0.0 || sidec = 0.0);
answer = "not a triangle";

else
answer = "scalene triangle";

}
}{code}

I would really appreciate any help you have to offer. I get error messages saying that I cannot compare boolean and double types but I'm not sure how else to write this. Please point me in the right direction.
• 10-06-2008, 12:35 AM
Fubarable
Please do not cross-post questions in multiple forums. This will frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. For this reason, many volunteers here and at the other sites refuse to help repeat offenders.

New To Java - Triangle Type Program
• 10-06-2008, 12:38 AM
jamesov89
I apologize for posting it on the sun forums but I figured that it would just help me to get the answer a bit more quickly. I would have posted that I had gotten the answer but again I apologize.
• 10-06-2008, 02:24 AM
Norm
Quote:

error messages saying that I cannot compare boolean and double types
Can you show the statement that generates this message?
• 10-06-2008, 02:30 AM
jamesov89
Here is an updated version of my code along with the error:

Quote:

import java.util.Scanner;
public class triangle {

public static void main(String[] args) {

double sidea;
double sideb;
double sidec;

Scanner in = new Scanner(System.in);
System.out.println("Enter the first side of a triangle: ");
sidea = in.nextDouble();
System.out.println("Enter the second side of a triangle: ");
sideb = in.nextDouble();
System.out.println("Enter the third side of a triangle: ");
sidec = in.nextDouble();

System.out.println("Sides" + " " + sidea + " " + sideb + " " + sidec);

if (((sidea * sidea) + (sideb * sideb)) == (sidec * sidec))
System.out.println("right triangle");
if (((sidea * sidea) + (sidec * sidec)) == (sideb * sideb))
System.out.println("right triangle");
if (((sidec * sidec) + (sideb * sideb)) == (sidea * sidea))
System.out.println("right triangle");

//right triangle

if ((sidea == sideb) && (sidea == sidec) && (sideb == sidec))
System.out.println("equilateral triangle");

//equilateral triangle

if (((sidea == sideb) || (sideb == sidec) || (sidea == sidec)) && !((sidea == sideb) && (sidea == sidec) && (sideb == sidec)))
System.out.println("isosceles triangle");

else (!((sidea == sideb) && (sidea == sidec) && (sideb == sidec)))
System.out.println("scalene triangle");

//scalene

if (((sidea + sideb) >= (sidec)) ||((sidea + sideb) >= (sideb)) ||((sideb +sidec) >= (sidea)))
System.out.println("not a triangle");

}
}

Quote:

Error:

F:\JCreatorV4\MyProjects\triangle\src\triangle.jav a:53: not a statement
else (!((sidea == sideb) && (sidea == sidec) && (sideb == sidec)))
^
F:\JCreatorV4\MyProjects\triangle\src\triangle.jav a:53: ';' expected
else (!((sidea == sideb) && (sidea == sidec) && (sideb == sidec)))
^
2 errors
Process completed.

I think my parenthesis are off but this is essentially the last step I have to make. Any ideas?
• 10-06-2008, 02:41 AM
Norm
There is a missing if
• 10-06-2008, 03:36 AM
jamesov89
I'm all done! Thank you for your help.