练习题:
使用键盘输入三个数字 a、b 和 c(建议三角形的边长),确定具有这些边的三角形是否存在。
package main;
import java.io.*;
/*
三角形法则
使用键盘输入三个数字 a、b 和 c(建议三角形的边长)。
确定具有这些边的三角形是否存在。
*/
public class test {
public static void main(String[] args) throws Exception {
// 从键盘获取
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String text = reader.readLine();
String text1 = reader.readLine();
String text2 = reader.readLine();
// 获取边长
// 字符串转换为 数字类型
int a = Integer.parseInt(text);
int b = Integer.parseInt(text1);
int c = Integer.parseInt(text2);
// 判断是否符合三角形法则,两边之和大于第三边
if (a+b > c && a+c > b && b+c > a) {
System.out.println("三角形可能存在。");
} else {
System.out.println("三角形不可能存在。");
}
}
}