类Loopy是公共的, 应在名为 Loopy.java 的文件中声明

代码是这样的:

public class Loopy {
   public static void main(String[] args){
   int x = 1;
   System.out.println("Before the Loop");
   while (x < 4) {
       System.out.println("In the loop");
       System.out.println("Value of x is " + x);
       x = x +1 ;
   }
   System.out.println("This is after the loop");
   }
}
运行报错:

Error:(3, 8) java: 类Loopy是公共的, 应在名为 Loopy.java 的文件中声明


不知道为什么,删除public就可以了。

猜你喜欢

转载自blog.csdn.net/weixin_41315469/article/details/79578814