- 1
Java program to take input of three sides of a triangle using standard input dialogue box compute the area of the triangle.
Write a Java program to take input of three sides of a triangle using standard input dialogue box compute the area of the triangle so the output using message dialogue box
4 Respostas
- 1
import javax.swing.JOptionPane;
public class TriangleTest
{
public static void main(String[] args)
{
String input;
int s1, s2, s3;
input = JOptionPane.showInputDialog("Enter s1");
s1 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Enter s2");
s2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Enter s2");
s3 = Integer.parseInt(input);
if((s1+s2)>s3 && (s1+s3)>s2 && (s2+s3)>s1)
{
int s=(s1+s2+s3)/2;
double area=Math.sqrt(s*(s-s1)*(s-s2)*(s-s3));
JOptionPane.showMessageDialog(null,"Area of triangle is " + area);
}
else
JOptionPane.showMessageDialog(null,"Triangle is not valid");
}
}
+ 2
Seems to be your homework. Anyways post your code here
0
Show. Your. Attempt.