用现在已学习的东西写的有点乱
public class ChangFangXing {
public int zhouChang(int a,int b) {
int c= (a+b)*2;
return c;
}
public int mianJi(int a,int b) {
int c= a*b;
return c;
}
}
public class Yuan {
public double zhouChang(int a) {
double b = 2*3.14*a;
return b;
}
public double mianJi(int a) {
double b = 3.14*a*a;
return b;
}
}
public class Main {
public static void main(String[] args) {
Scanner jp = new Scanner(System.in);
while (true) {
System.out.println("请输入你要求的图像(1:长方形 2:圆):");
int p1 = jp.nextInt();
if (p1 == 1) {
while (true) {
System.out.println("求周长还是面积(1:周长 2:面积):");
int p2 = jp.nextInt();
if (p2 == 1) {
System.out.println("请输入长宽:");
int p3 = jp.nextInt();
int p4 = jp.nextInt();
ChangFangXing zc = new ChangFangXing();
System.out.println(zc.zhouChang(p3, p4));
break;
} else if (p2 == 2) {
System.out.println("请输入长宽:");
int p5 = jp.nextInt();
int p6 = jp.nextInt();
ChangFangXing zc = new ChangFangXing();
System.out.println(zc.zhouChang(p5, p6));
break;
} else {
System.out.println("请输入正的周长或者面积");
}
}
} else if (p1 == 2) {
while (true) {
System.out.println("求周长还是面积(1:周长 2:面积):");
int p7 = jp.nextInt();
if (p7 == 1) {
System.out.println("请输入半径:");
int p8 = jp.nextInt();
Yuan y = new Yuan();
System.out.println(y.zhouChang(p8));
break;
} else if (p7 == 2) {
System.out.println("请输入长宽:");
int p9 = jp.nextInt();
Yuan y = new Yuan();
System.out.println(y.zhouChang(p9));
break;
} else {
System.out.println("请输入周长或者面积");
}
}
}else{
System.out.println("请输入正确的数字(1:长方形 2:圆)");
}
}
}
} |
|