How to calculate a triangle area
double a = Double.parseDouble(jTextField1.getText());
double b = Double.parseDouble(jTextField2.getText());
double c = Double.parseDouble(jTextField3.getText());
double area1;
double area2;
double semip;
if (((a+b)>c)&&((a+c)>b)&&((b+c)>a))
{
jTextField6.setText("form a triangle");
semip = (a+b+c)/2;
area1 = (semip*(semip-a)*(semip-b)*(semip-c));
area2 = (Math.sqrt(area1));
jTextField4.setText(String.valueOf(NumberFormat.getNumberInstance().format(area2)));
//jTextField4.setText(String.valueOf(Math.round(area2))); - full the number
if (a==b && b==c)
{
jTextField5.setText("equilateral triangle");
}
else if (a==b || b==c || a ==c)
{
jTextField5.setText("isosceles triangle");
}
else
{
jTextField5.setText("scalene triangle");
}
}
else
{
jTextField6.setText("not form a triangle");
}
Subscribe to:
Posts (Atom)
No comments:
Post a Comment