Results 1 to 7 of 7
Thread: Triangle Sides program
 10062008, 01:13 AM #1Member
 Join Date
 Sep 2008
 Posts
 21
 Rep Power
 0
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;
String answer;
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));
answer = "isosceles";
if (sidea = 0.0  sideb = 0.0  sidec = 0.0);
answer = "not a triangle";
else
answer = "scalene triangle";
System.out.println(answer);
}
}{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.

Please do not crosspost 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 crossposted thread. For this reason, many volunteers here and at the other sites refuse to help repeat offenders.
New To Java  Triangle Type Program
 10062008, 01:38 AM #3Member
 Join Date
 Sep 2008
 Posts
 21
 Rep Power
 0
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.
 10062008, 03:24 AM #4error messages saying that I cannot compare boolean and double types
 10062008, 03:30 AM #5Member
 Join Date
 Sep 2008
 Posts
 21
 Rep Power
 0
Here is an updated version of my code along with the error:
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");
}
}
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?
 10062008, 03:41 AM #6
There is a missing if
 10062008, 04:36 AM #7Member
 Join Date
 Sep 2008
 Posts
 21
 Rep Power
 0
Similar Threads

Triangle
By jkswebsite in forum New To JavaReplies: 8Last Post: 01102009, 03:08 PM 
[SOLVED] How do I make a triangle?
By Zebra in forum Java AppletsReplies: 6Last Post: 05202008, 03:23 PM 
Pascal Triangle help
By Magic101 in forum New To JavaReplies: 4Last Post: 05012008, 08:51 PM 
Making triangle
By banie in forum New To JavaReplies: 4Last Post: 02022008, 12:23 PM 
Need help making ball move and bounce off of sides of JPanel
By adlb1300 in forum New To JavaReplies: 2Last Post: 12012007, 08:48 AM
Bookmarks