Results 1 to 7 of 7
  1. #1
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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

  3. #3
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    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.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    error messages saying that I cannot compare boolean and double types
    Can you show the statement that generates this message?

  5. #5
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    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?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    There is a missing if

  7. #7
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

Similar Threads

  1. Triangle
    By jkswebsite in forum New To Java
    Replies: 8
    Last Post: 01-10-2009, 02:08 PM
  2. [SOLVED] How do I make a triangle?
    By Zebra in forum Java Applets
    Replies: 6
    Last Post: 05-20-2008, 02:23 PM
  3. Pascal Triangle help
    By Magic101 in forum New To Java
    Replies: 4
    Last Post: 05-01-2008, 07:51 PM
  4. Making triangle
    By banie in forum New To Java
    Replies: 4
    Last Post: 02-02-2008, 11:23 AM
  5. Replies: 2
    Last Post: 12-01-2007, 07:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •