哪位java高手能帮我解答这道题啊?

来源:百度知道 编辑:UC知道 时间:2024/06/18 16:42:44
从键盘输入三个数,判断是否能组成三角形,如果能,求出三角形的面积和周长,如果不能,再重新输入,直到能组成三角形为之。

不用那么麻烦,这个事我自己写的
import java.lang.Math;
import java.util.Scanner;

public class Test {
public static void main(String[] args) {
int s[] = new int[3];//接受数据的数组
double zc=0;//周长
double m=0;//面积
while (true) {
for (int j = 0; j < 3; j++) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
s[j] = Integer.parseInt(input);
}
double a = s[0];
double b = s[1];
double c = s[2];
if (a + b > c || a + c > b || b + c > a) {
zc = a + b + c;
double x = (a + b + c) / 2;
double d = x * (x - a) * (x - b) * (x - c);
m = Math.sqrt(d);
break;
} else{
System.out.println("数据错误请重新输入");
}
}
System.out.println("周长是 "+zc);
System.out.println("面积是 "+m);
}
}