错误发生在我张贴评论*的地方,第一个错误在开关中的i上说我需要;,第二个错误在第一个案例上说它是孤立的。我非常困惑,如果可能的话,我想要一个正在发生的事情的解释。
public class Shape3D_Client{
public static final int MAX = 6;
public static void main (String [] args){
Shape3D[] shapes = new Shape3D[MAX];
shapes[0] = new SquarePyramid(37,20);
shapes[1] = new Sphere(20);
shapes[2] = new RetangularPrism(10, 20, 37);
shapes[3] = new Cube(10);
shapes[4] = new Cylinder(10, 20);
shapes[5] = new CircularCone(10, 20);
for(int i = 0; i < shapes.length; i++){
System.out.println("\nThis is a ");
Switch (i){//*********************************
case 0://***********************************
System.out.println("square pyramid. ");
break;
case 1:
System.out.println("Sphere. ");
break;
case 2:
System.out.println("RetangularPrism. ");
break;
case 3:
System.out.println("Cube. ");
break;
case 4:
System.out.println("Cylinder. ");
break;
case 5:
System.out.println("CircularCone. ");
break;
}//closes switch
System.out.printf("Area = %.2f", shapes[i].getArea());
System.out.printf(". Volume = %.2f\n", shapes[i].getVolume());
System.out.println("Output calling the method printInfo - polymorphism at work!");
printInfo(shapes[i]);
System.out.println("---------------------------------------------------- ------------------------------------");
}//closes for loop
}//closes main
public static void printInfo(Shape3D s) {
System.out.println(s);
System.out.printf("Area = %.2f", s.getArea());
System.out.printf(". Volume = %.2f\n", s.getVolume());
}//closes method
}//closes class发布于 2015-10-07 22:34:26
Java区分大小写。您需要使用
switch(i)而不是
Switch(i)https://stackoverflow.com/questions/32994960
复制相似问题