首页 > 试题广场 >

这一页的Java程序代码代表一份完整的源文件。你的任务是要扮

[问答题]
这一页的Java程序代码代表一份完整的源文件。你的任务是要扮演编译器角色并判断哪个程序可以编译过关。如果有问题,哪里需要修改?
A
class Exerciselb{
 public static void main(String [] args) {
  int x = 1;
  while ( x < 10 ) {
    if ( x > 3) {
     System.out.println("big x");
    }
   }
  }
 }
B
public static void main(String [] args) {
    int x = 5;
    while ( x > 1) {
      x = x - 1;
      if ( x < 3) {
       System.out.println("small x");
      }
    }
}
C
class Exerciselb{
    int x = 5;
    while ( x > 1) {
      x = x - 1;
      if ( x < 3) {
       System.out.println("small x");
      }
    }
}

1 循环会一直重复

2没有类声明

3while 在方法体内

发表于 2019-09-12 09:37:53 回复(1)
class Exerciselb{
 public static void main(String [] args) {
  int x = 1;
  while ( x < 10 ) {
    x = x + 1;//没有这么一行就变成了死循环
    if ( x > 3) {
     System.out.println("big x");
    }
   }
  }
 }

class Exerciselb{//没有类是无法编译成功的
    public static void main(String [] args) {
        int x = 5;
        while ( x > 1) {
          x = x - 1;
          if ( x < 3) {
           System.out.println("small x");
          }
        }
    }
}

class Exerciselb{
    public static void main(String[] args){//while必须在方法里面循环
        int x = 5;
        while ( x > 1) {
          x = x - 1;
          if ( x < 3) {
           System.out.println("small x");
          }
        }
    }
}

发表于 2019-08-13 10:41:33 回复(0)
A 没有循环控制条件,x一直是1 B 没有类无法输出 C 没有main方法,找不到执行的入口,执行不了
编辑于 2021-03-17 15:57:58 回复(0)
A.死循环,对x本身无操作
B.缺少类
C.缺少main函数方法
编辑于 2020-07-02 17:21:37 回复(0)
<p>a没有设置迭代条件 会导致死循环</p>
发表于 2020-05-23 07:20:16 回复(0)
<p>第一个可以编译通过,第二个缺乏类,第三个缺方法</p>
发表于 2020-04-30 23:22:50 回复(0)
**c要加个方法体**
class Exerciselb{
public static void main(String[] args){
    int x = 5;
    while ( x > 1) {
      x = x - 1;
      if ( x < 3) {
       System.out.println("small x");
      }
    }
}
发表于 2020-04-18 22:40:42 回复(0)
A可以有运行,B的while循环条件的改下,C无main
发表于 2019-11-18 23:43:31 回复(0)