Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## 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

• First thing first: learn the difference between Java and Javascript......

• and the second thing?

• Originally Posted by gingergib
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.

• 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

• 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

• Originally Posted by gingergib
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.

• 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```

• 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

• 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

• Originally Posted by _Aerospace_Eng_
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
•