Java Switch语句由于某些原因与案例8不同。编译器的行为真的很奇怪

Java Switch语句由于某些原因与案例8不同。编译器的行为真的很奇怪,java,syntax-error,Java,Syntax Error,代码如下: public static void main(String args[]) { int i=0; int m=0; double scale; boolean exit; Shape[] s = new Shape[10]; while(exit !=true) { System.out.print("\nChoose an option:

代码如下:

public static void main(String args[])
    {
        int i=0;
        int m=0;
        double scale;
        boolean exit;
        Shape[] s = new Shape[10];
        while(exit !=true)
        {
            System.out.print("\nChoose an option:\n"+
                    "1-Add a new circle\n"+
                    "2-Add a new rectangle\n"+
                    "3-Delete all shapes\n"+
                    "4-Scale all shapes\n"+
                    "5-Display perimeter of all shapes\n"+
                    "6-Display the area of all shapes\n"+
                    "7-Enter scale factor\n"+
                    "8-Exit program\n");

            Scanner input = new Scanner(System.in);
            m=input.nextInt();


            if(i<=9)
            {
                switch (m)
                {


                 case 1: Circle c = new Circle(0);
                         s[i]=c;
                         i++;
                         break;
                 case 2: Rectangle r = new Rectangle(1,1);
                         s[i]=r;
                         i++;
                         break;

                 case 3: s=null;
                         i=0;
                         break;
                 case 4: for(i=0; i<s.length; i++)
                         {
                             s[i].scaleShape();
                         }
                         break;
                 case 5: for(i=0; i<s.length; i++)
                         {
                            if(s[i] != null)
                            {   
                                System.out.println(s[i].getPerimeter());
                            }
                         }
                         break;
                 case 6: for(i=0; i<s.length; i++)
                         {
                            if(s[i] != null)
                            {
                                System.out.println(s[i].getArea());
                            }
                         }
                         break;
                 case 7: do
                         {
                            System.out.println("\nEnter scale factor");
                            scale=input.nextDouble();
                         }
                         while(scale<0);
                         Shape.setScaleFactor(scale);

                         }
                         break;

                 case 8: System.out.println("Do you want to quit?");
                         break; //Nothing here since loop should terminate it.



                 //default: System.out.println("Number must be 1-8");
                         // break;


              } 

         }
     }
   }
publicstaticvoidmain(字符串参数[])
{
int i=0;
int m=0;
双尺度;
布尔出口;
形状[]s=新形状[10];
while(退出!=真)
{
System.out.print(“\n选择一个选项:\n”+
“1-添加一个新圆圈\n”+
“2-添加新矩形\n”+
“3-删除所有形状\n”+
“4-缩放所有形状\n”+
“5-显示所有形状的周长\n”+
“6-显示所有形状的区域\n”+
“7-输入比例因子\n”+
“8-退出程序”;
扫描仪输入=新扫描仪(System.in);
m=输入.nextInt();

如果(i
}/您的问题是7:

案例7:do
{
System.out.println(“\n输入比例因子”);
scale=input.nextDouble();
}

while(scale
while(scale每个人都指出代码中有一个额外的括号,但我们没有指出它的来源

while(scale<0); // <-- This isn't going to work....
    Shape.setScaleFactor(scale);
}

while(在案例7中scaleEthere是一个do-while循环,所以我认为它在那里没有问题。是的,这就是问题所在,原始代码说
while(scaleI也可能是错误的,没有上下文,但它跳出来让我觉得很奇怪;)修复了语法错误,但几乎肯定是错误的。语句
while(scale
case 7: do
        {
             System.out.println("\nEnter scale factor");
             scale=input.nextDouble();
        }
        while(scale<0);
        Shape.setScaleFactor(scale);

        }
while(scale<0);
Shape.setScaleFactor(scale);

} // Remove this parenthesis.
break;
while(scale<0); // <-- This isn't going to work....
    Shape.setScaleFactor(scale);
}
while(scale<0) {
    Shape.setScaleFactor(scale);
}