java编写应用程序,读取用户输入的3个非0数据,判断并输出这3个值看能否构成一个三角形的3条边

2025年03月25日 02:51
有1个网友回答
网友(1):

public class Test1{

public static void main(String args[]){
while(true){
System.out.println("输入3个数字,中间用/隔开……");
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
try {
String str[] = buff.readLine().split("/");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int c = Integer.parseInt(str[2]);
if((a+b>c) && (a+c>b) &&(b+c>a)){
System.out.println("您输入的3个数字可以组成三角形");
}else{
System.out.println("您输入的3个数字不能组成三角形,请重新输入");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

}