Java基础实验,求大神用比较基础的Java语言解答
使用swing的JTextField实现。
用java面向对象思想求三角形的面积和周长: https://blog.csdn.net/com_it/article/details/68958657
public static void show() throws Exception{
System.out.println("*************************************\n" +
"***需求: 用户输入三角形的三条边,求其周长和面积***\n************************************");
Scanner scan=new Scanner(System.in);
System.out.println("请输入三角的第一条边:");
String str=scan.nextLine();
while(!Check.isNumber(str)){
System.out.println("你输入的格式不正确,请重新输入:");
str=scan.nextLine();
}
double a1=Double.parseDouble(str);
//第二条边
System.out.println("请输入三角形的第二条边:");
str=scan.nextLine();
while(!Check.isNumber(str)){
System.out.println("你输入的格式不正确,请重新输入:");
str=scan.nextLine();
}
double a2=Double.parseDouble(str);
//第三条边
System.out.println("请输入三角形的第三条边:");
str=scan.nextLine();
while(!Check.isNumber(str)){
System.out.println("你输入的格式不正确,请重新输入:");
str=scan.nextLine();
}
double a3=Double.parseDouble(str);
//判断三角形是否成立
while(!Check.isTriangle(a1, a2, a3)){
System.out.println("你输入的三条边不符合三角形成立的条件\n请重新开始输入:");
show();
}
System.out.println("该三角形的周长为:"+getPerimeter(a1,a2,a3)+" 面积为:"+getArea(a1,a2,a3));
throw new Exception(); //强制退出递归
}