错误发生在我发布了评论*的第一个错误,在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
答案 0 :(得分:1)
Java区分大小写。你需要使用
switch(i)
而不是
Switch(i)