package student;
import java.util.Scanner;
public class mianji {
public static void main(String[] args){
System.out.println("形状的类型\n1.长方形\n2.圆形\n3.三角形\n4.退出");
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
if(a<=4&&a>=1){
switch(a){
case 1:
System.out.println("Please enter length");
float b=scan.nextFloat();
System.out.println("Please enter highth");
float c=scan.nextFloat();
if(b>=0&&c>=0){
System.out.println("Area of the rectangle is:"+(c*b));
}else{System.out.println("b and c can't be zero");}
case 2:
System.out.println("Please enter redius");
float d=scan.nextFloat();
if(d>=0){
System.out.println("Area of the cylnder is:"+(d*d*Math.PI));
}else{System.out.println("d can't be zero");}
case 3:
System.out.println("Plese enter A");
float A=scan.nextFloat();
System.out.println("Plese enter B");
float B=scan.nextFloat();
System.out.println("Plese enter C");
float C=scan.nextFloat();
if(A>=0&&B>=0&&C>=0){
while(true){if(A+B>C){
float p=(A+B+C)/2;
float sum=(float) Math.sqrt((p*(p-A)*(p-B)*(p-C)));
System.out.println("The triangle area is "+sum);
}
else{
System.out.println("Three sides can not constitute a triangle");
}
}}else{
System.out.println("A,B,C can't be zero");
}
case 4:
System.out.println("Bye Bye");
}
}
else{
System.out.println("Please enter 1~4 number");
}
}
}
三角形部分是case 3 ;然后要怎么弄才能可以计算完条回到选择形状的界面继续算