English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am trying to write a Java program using JCreator called Triangles that asks the user to enter three whole numbers representing the angles of a triangle. The purpose of the program is to determine, based on these numbers if the triangle is equalateral, isosceles or right angles.

If all angles are equal then I want to output the sentence using System.out.print, stating that this is an equalateral triangle. If only two angles are equal I want the sentence to state that this is an isosceles triangle. If any of the angles are 90o then I want to output a sentence stating that this is a right angled triangle.

So far I have:
String triangle(double angle1, double angle2, double angle3) {
if( (angle1 + angle2 + angle3) !=180)
return "Not a triangle";
else{
if(angle1 == angle2 || angle1 == angle3 || angle2 == angle3)
return "Isosceles";
if(angle1 == 90.0 || angle2 == 90.0 || angle3 == 90.0)
return "Right";
if(angle1 == angle2 && angle1 == angle3)
return "Equalateral";
}

}

2006-10-28 08:43:00 · 2 answers · asked by Princess Peach 3 in Computers & Internet Programming & Design

2 answers

String triangle(double angle1, double angle2, double angle3)
{
if( ( angle1 + angle2 + angle3 ) != 180.0 )
return "Not a triangle";
else
{
if( angle1 == 90.0 ||
angle2 == 90.0 ||
angle3 == 90.0 )
{
return "Right";
}

if ( angle1 == angle2 && angle2 == angle3 )
{
return "Isosceles";
}

if ( angle1 == angle2 ||
angle1 == angle3 ||
angle2 == angle3 )
{
return "Equalateral";
}
}

return null;
}

2006-10-28 10:00:48 · answer #1 · answered by Daniel H 5 · 0 0

I'm not a Java programmer, but if you're looking for how to set up the System.out.print string, it will probably look something like this:

System.out.print "This triangle is: " + triangle(angle1, angle2, angle3)

2006-10-28 15:56:42 · answer #2 · answered by Good Times, Happy Times... 4 · 0 2

fedest.com, questions and answers