首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Switch语句客户端问题

Switch语句客户端问题
EN

Stack Overflow用户
提问于 2015-10-07 22:28:31
回答 1查看 23关注 0票数 1

错误发生在我张贴评论*的地方,第一个错误在开关中的i上说我需要;,第二个错误在第一个案例上说它是孤立的。我非常困惑,如果可能的话,我想要一个正在发生的事情的解释。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2015-10-07 22:34:26

Java区分大小写。您需要使用

代码语言:javascript
复制
switch(i)

而不是

代码语言:javascript
复制
Switch(i)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32994960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档