Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    triangles program

    i need to write a program in java script which asks the user to enter 3 whole numbers representing the angles of a triangle. the program will then say wether the triangle is equalateral, isoseles or right angled. jus the most basic program using java things is needed. i wud appreciate any help as all i can come up with is the following:
    public class triangles1
    {
    public static void main(string []args)
    {
    system.out.println("Please note that all angles must total 180!");
    int ang_1 = getScannerInput.anInt("Enter a number from 1-180");
    int ang_2 = getScannerInput.anInt("Enter a second number from 1-180");
    int ang_3 = getScannerInput.anInt("Enter a third number from 1-180");
    int tot = ang_1+ang_2+ang_3;
    {
    if (int tot >= 180)
    system.out.println("invalid angles entered");
    }
    }
    }// end class

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First thing first: learn the difference between Java and Javascript......
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and the second thing?

  • #4
    New Coder
    Join Date
    Oct 2005
    Posts
    49
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gingergib View Post
    and the second thing?
    if(total>=180)
    should be changed to:
    if(total>180)
    because a triangle has 180 degrees on the inside.
    if(total==180){
    if(ang_1==90||ang_2==90||ang_3==90){
    system.whatever("right triangle");
    }
    if((ang_1==ang_2&&ang_1!=ang_3)||(ang_1==ang_3&&ang_1!=ang_2)||(ang_2==ang_3&&ang_2!=ang_1){
    system.blahblah("isosceles triangle");
    }
    if(ang_1==ang_2&&ang_2==ang_3){
    system.c++isbetterthanjava("equilateral triangle");
    }
    }
    is one way to do it. I'm sure there are other ways, though.

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers mate. big help. if i posted wrongly here im sorry but good to c ppl r still helpful these days. thanks again, il try that

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i now got the following but it still wont work. any1 know how i cud touch it up?
    :
    public class triangles1
    {
    public static void main(String [] args)
    {
    int ang_1 = input from keyboard.anInt("enter value here");
    int ang_2 = input from keyboard.anInt("enter number here");
    int ang_3 = input from keyboard.anInt("enter digit here");
    int total = ang_1+ang_2+ang_3;
    {
    if(total!=180)
    System.out.println("please re-enter angles so as they equal 180");
    }
    {
    if(ang_1==90||ang_2==90||ang_3==90)
    System.out.println("right triangle");
    }
    {
    if((ang_1==ang_2&&ang_1!=ang_3)||(ang_1==ang_3&&ang_1!=ang_2)||(ang_2==ang_3&&ang_2!=ang_1))
    System.out.println("isosceles triangle");
    }
    {
    if(ang_1==ang_2&&ang_2==ang_3)
    System.out.println("equilateral triangle");
    }
    }}}// end class triangles1

  • #7
    New Coder
    Join Date
    Oct 2005
    Posts
    49
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gingergib View Post
    i now got the following but it still wont work. any1 know how i cud touch it up?
    :
    public class triangles1
    {
    public static void main(String [] args)
    {
    int ang_1 = input from keyboard.anInt("enter value here");
    int ang_2 = input from keyboard.anInt("enter number here");
    int ang_3 = input from keyboard.anInt("enter digit here");
    int total = ang_1+ang_2+ang_3;
    {
    if(total!=180)
    System.out.println("please re-enter angles so as they equal 180");
    }
    {
    if(ang_1==90||ang_2==90||ang_3==90)
    System.out.println("right triangle");
    }
    {
    if((ang_1==ang_2&&ang_1!=ang_3)||(ang_1==ang_3&&ang_1!=ang_2)||(ang_2==ang_3&&ang_2!=ang_1))
    System.out.println("isosceles triangle");
    }
    {
    if(ang_1==ang_2&&ang_2==ang_3)
    System.out.println("equilateral triangle");
    }
    }}}// end class triangles1


    Your braces are all messed up. You need to make sure they all match up.

  • #8
    New Coder
    Join Date
    Oct 2005
    Posts
    49
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Code:
    public class triangles1{
                public static void main(String [] args){
                   int ang_1 = input from keyboard.anInt("enter value here");
                   int ang_2 = input from keyboard.anInt("enter number here");
                   int ang_3 = input from keyboard.anInt("enter digit here");
                   int total = ang_1+ang_2+ang_3;
                   if(total!=180){
                       System.out.println("please re-enter angles so as they equal 180");
                   }
                   else{
                       if(ang_1==90||ang_2==90||ang_3==90){
                           System.out.println("right triangle");
                       }
                       if((ang_1==ang_2&&ang_1!=ang_3)||(ang_1==ang_3&&ang_1!=ang_2)||(ang_2==ang_3&&ang_2!=ang_1)){
                           System.out.println("isosceles triangle");
                       }
                       if(ang_1==ang_2&&ang_2==ang_3){
                           System.out.println("equilateral triangle");
                       }
                    }
                }
            }//end class
    Last edited by jakbo; 10-29-2006 at 08:36 PM.

  • #9
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ur a legend jakbo!! things finally workin fine. so after a sleepless weekend and a lot of beer cigs an takeaway food i finnally beginnin to understand this stuff. cheers again boss

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I hope you get an A on your assignment. You should read this thread on how homework assignments should be handled here: http://www.codingforums.com/showthread.php?t=53446
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    New Coder
    Join Date
    Oct 2005
    Posts
    49
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    I hope you get an A on your assignment. You should read this thread on how homework assignments should be handled here: http://www.codingforums.com/showthread.php?t=53446
    Yeah, I shouldn't have done that. After I posted, I realized people need to think about this stuff, if they truly want to learn about it.

    After thinking about it a little, though, it's still not quite right, because it doesn't take into consideration if someone enters 0 for one of the angles.


  •  

    Posting Permissions

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