单选题public class WhileFoo {   public static void main (String args) {   int x= 1, y = 6;   while (y--) {x--;}   system.out.printIn(“x=” + x “y =” + y);   }   }   What is the result?()AThe output is x = 6 y = 0BThe output is x = 7 y = 0CThe output is x = 6 

题目
单选题
public class WhileFoo {   public static void main (String args) {   int x= 1, y = 6;   while (y--) {x--;}   system.out.printIn(“x=” + x “y =” + y);   }   }   What is the result?()
A

 The output is x = 6 y = 0

B

 The output is x = 7 y = 0

C

 The output is x = 6 y = -1

D

 The output is x = 7 y = -1

E

 Compilation will fail.


相似考题
更多“单选题public class WhileFoo {   public static void main (String args) {   int x= 1, y = 6;   while (y--) {x--;}   system.out.printIn(“x=” + x “y =” + y);   }   }   What is the result?()A  The output is x = 6 y = 0B  The output is x = 7 y = 0C  The output is ”相关问题
  • 第1题:

    下面程序段的输出结果为( )。 package test; public class ClassA { int x=20: static int y=6; public static void main(String args[]) { ClassB b=new ClassB; go(10); System.out.println("x="+b.x); } } class ClassB { int X; void go(int y) { ClassA a=new ClassA; x=a.Y ; } }

    A.x=10

    B.x=20

    C.x=6

    D.编译不通过


    正确答案:C
    C。【解析】本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的90方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量Y的值。从main方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给X和Y赋值,X=a.Y后,X值为6,再返回去执行System.out.println("x="+b.x)语句,输出为x=6,可见,正确答案为选项C。

  • 第2题:

    执行如下语句之后,输出的结果是______。 public class ex24 { public static void main(String[] args) { int x=5,y=3; x+=X-- *--y; System.out.println{x); } }

    A.0

    B.1

    C.true

    D.false


    正确答案:C

  • 第3题:

    以下程序的输出结果为:public class test {public static void main(String args[]) {int x=1,y=1,z=1;if (x--==1&&y++==1||z++== 1、System.out.println("x="+x+",y="+y+",z="+z);}}

    A. x=0,y=2,z=1

    B. x=1,y=2,z=1

    C. x=0,y=1,z=1

    D. x=0,y=2,z=2


    正确答案:A

  • 第4题:

    1. public class X implements Runnable(  2. private int x;  3. private int y;  4.    5. public static void main(String[]args)  6. X that = new X();  7. (new Thread(that)).start();  8. (new Thread(that)).start();  9. )  10.    11. public void run()  (  12. for (;;)  (  13. x++; 14. y++;  15. System.out.printIn(“x=” + x + “, y = ” + y);  16.     ) 17. ) What is the result?()

    • A、 Errors at lines 7 and 8 cause compilation to fail.
    • B、 The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”).
    • C、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”).
    • D、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”).

    正确答案:D

  • 第5题:

    Less Test{    public static void main(String[] args){   for(int x=0;x<7;++x){  int y=2;   x=++y;   }   System.out.println(“y=”+y);   }   }   结果为:()  

    • A、y=5
    • B、y=6
    • C、 y=7
    • D、y=8
    • E、编译失败
    • F、运行时异常被抛出

    正确答案:E

  • 第6题:

    public class X implements Runnable (   private int x;   private int y;    public static void main(String args) (   X that = new X();   (new Thread(that)) . start( );   (new Thread(that)) . start( );   )    public synchronized void run( ) (    for (;;) (    x++;    y++;    System.out.printIn(“x = “ + x + “, y = “ + y);    )   )    )   What is the result?()

    • A、 An error at line 11 causes compilation to fail.
    • B、 Errors at lines 7 and 8 cause compilation to fail.
    • C、 The program prints pairs of values for x and y that might not always be the same on the same line  (for example, “x=2, y=1”)
    • D、 The program prints pairs of values for x and y that are always the same on the same line (forexample, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by  “x=1, y=1”)
    • E、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by  “x=2s, y=2”)

    正确答案:E

  • 第7题:

    public class IfTest (  public static void main(string[]args) {  int x = 3;  int y = 1;  if (x = y)  system.out.printIn(“Not equal”);  else  system.out.printIn(“Equal”);  }  )   What is the result?()      

    • A、 The output is “Equal”
    • B、 The output in “Not Equal”
    • C、 An error at line 5 causes compilation to fall.
    • D、 The program executes but does not print a message.

    正确答案:C

  • 第8题:

    int x = 1, y =6;  while (y--) {  x++;  }  System.out.println(“x =” + x + “y =” +y); What is the result?()  

    • A、 x = 6 y = 0
    • B、 x = 7 y = 0
    • C、 x = 6 y = -1
    • D、 x = 7 y = -1
    • E、 Compilation fails.

    正确答案:E

  • 第9题:

    单选题
    public class IfTest (   public static void main(stringargs) {   int x = 3;  int y = 1;   if (x = y)   system.out.printIn(“Not equal”);   else   system.out.printIn(“Equal”);   }   )   What is the result?()
    A

     The output is “Equal”

    B

     The output in “Not Equal”

    C

     An error at line 5 causes compilation to fall.

    D

     The program executes but does not print a message.


    正确答案: C
    解析: 暂无解析

  • 第10题:

    单选题
    int x = 1, y =6;  while (y--) {  x++;  }  System.out.println(“x =” + x + “y =” +y); What is the result?()
    A

     x = 6 y = 0

    B

     x = 7 y = 0

    C

     x = 6 y = -1

    D

     x = 7 y = -1

    E

     Compilation fails.


    正确答案: E
    解析: A ‘while’ statement can only evaluate a Boolean expression. The expression while(y--) returns an int rather than a Boolean. Therefore, the correct answer is E. 

  • 第11题:

    单选题
    public class X implements Runnable (  private int x;  private int y;  public static void main(String [] args) (  X that = new X();  (new Thread(that)) . start( );  (new Thread(that)) . start( );  )  public synchronized void run( ) (  for (;;) (   x++;  y++;  System.out.printIn(“x = “ +  x  + “, y = “ + y);  )  )  )   What is the result?()
    A

     An error at line 11 causes compilation to fail.

    B

     Errors at lines 7 and 8 cause compilation to fail.

    C

     The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”)

    D

     The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”)

    E

     The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=2s, y=2”)


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    class Foo {  public static void main(String [] args) {  int x = 0;  int y = 4;  for(int z=0; z 〈 3; z++, x++) {  if(x 〉 1 & ++y 〈 10) y++;  }  System.out.println(y);  }  }  结果是什么?()
    A

    6

    B

    7

    C

    8

    D

    10


    正确答案: B
    解析: 暂无解析

  • 第13题:

    下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

    A.x=10

    B.x=20

    C.x=6

    D.编译不通过


    正确答案:C
    解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println(”x=”+b.x)语句,输出为x=6,可见,正确答案为选项C。

  • 第14题:

    执行如下语句之后,输出的结果是______。 public class ex36 { public static void main(String[] args) { int x=-6, y=6; x=x+y--; System.out.println (x); } }

    A.-12

    B.12

    C.-1

    D.0


    正确答案:D

  • 第15题:

    阅读以下C++代码,填充(1)~(5)的空缺,将解答填入答题纸的对应栏内。 【说明】在下面程序横线处填上适当的字句,使其输出结果为:x=5x=6y=7x=8z=9【程序】#include<iostream.h>class X1{int x;(1):X1(int xx=0){x=xx;}(2)void Output()(cout<<"x="<<x<<end;}};(3)Y1:public X1{int y;public:Y1(int xx=0,int yy=0):X1(xx){y=yy;}(2)void Output(){(4)Output();cout<<"y="<<y<<end1;}};class Z1:pubtic X1{int z:(5):Z1(int xx=0,int zz=0):X1(xx){z=zz;}②void Output(){X1::Output();cout<<"z="<<z<<end1;}};void main(){X1 a(5);Y1 b(6,7);Z1 c(8,9);X1*p[3]={&a,&b,&c};For(int i=0;i<3;i++){p[i]-->Output();cout<<end1;}}


    答案:
    解析:
    (1)public
    (2)virtual
    (3)class
    (4)X1::
    (5)public
    【解析】

    通过对比三个类的定义就可以发现,在类X1和Z1的定义中缺少类的成员属性声明,而类一般将成员变量声明为公有的、私有的或受保护的三种类型中的一种,在类的定义中,我们一般将类的构造函数放在公有的属性下面,在题目中只能选择公有的属性了,因此,第1空和第5空中应该填“public”。对三个类的定义进行仔细观察后,我们同样可以发现,每个类中都定义了一个同名函数Output(),而且在后两个类的函数体中调用了函数Output(),由此,我们应该想到虚函数。虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数。因此,第2空应该填“virtual”。第3空就简单了,考查类的定义,应该填类的标识符“class”。从程序中我们可以看到,类Y1和Z1都以公有的方式继承类X1。从输出的结果来分析,类Y1和Z1都输出了两个数,但单从类Z1的函数来看,只能输出一个变量的值z,因此,可以发现在类Z1中应该和类Y1一样,都调用了类X1的函数Output(),因此,第4空的答案为“X1::”。

  • 第16题:

    class DemoApp{  public static void main(String[] args){  int x = 5; int y = ++x + x++; S ystem.out.println(“y=”+y+”,x=”+x);  }  }  以上程序运行后的输出结果是哪项?() 

    • A、y=10,x=5
    • B、y=11,x=6
    • C、y=12,x=7
    • D、y=11,x=7

    正确答案:C

  • 第17题:

    public class WhileFoo {  public static void main (String []args)   {  int x= 1, y = 6;  while (y--)  {x--;}  system.out.printIn(“x=” + x “y =” + y);  }  }   What is the result?()  

    • A、 The output is x = 6 y = 0
    • B、 The output is x = 7 y = 0
    • C、 The output is x = 6 y = -1
    • D、 The output is x = 7 y = -1
    • E、 Compilation will fail.

    正确答案:E

  • 第18题:

    class Foo {  public static void main(String [] args) {  int x = 0;  int y = 4;  for(int z=0; z 〈 3; z++, x++) {  if(x 〉 1 & ++y 〈 10) y++;  }  System.out.println(y);  }  }  结果是什么?()  

    • A、6
    • B、7
    • C、8
    • D、10

    正确答案:C

  • 第19题:

    public class IfTest (   public static void main(stringargs) {   int x = 3;  int y = 1;   if (x = y)   system.out.printIn(“Not equal”);   else   system.out.printIn(“Equal”);   }   )   What is the result?()

    • A、 The output is “Equal”
    • B、 The output in “Not Equal”
    • C、 An error at line 5 causes compilation to fall.
    • D、 The program executes but does not print a message.

    正确答案:C

  • 第20题:

    单选题
    public class IfTest (  public static void main(string[]args) {  int x = 3;  int y = 1;  if (x = y)  system.out.printIn(“Not equal”);  else  system.out.printIn(“Equal”);  }  )   What is the result?()
    A

     The output is “Equal”

    B

     The output in “Not Equal”

    C

     An error at line 5 causes compilation to fall.

    D

     The program executes but does not print a message.


    正确答案: A
    解析: 暂无解析

  • 第21题:

    单选题
    Less Test{    public static void main(String[] args){   for(int x=0;x<7;++x){  int y=2;   x=++y;   }   System.out.println(“y=”+y);   }   }   结果为:()
    A

    y=5

    B

    y=6

    C

     y=7

    D

    y=8

    E

    编译失败

    F

    运行时异常被抛出


    正确答案: D
    解析: 暂无解析

  • 第22题:

    单选题
    public class WhileFoo {  public static void main (String []args)   {  int x= 1, y = 6;  while (y--)  {x--;}  system.out.printIn(“x=” + x “y =” + y);  }  }   What is the result?()
    A

     The output is x = 6 y = 0

    B

     The output is x = 7 y = 0

    C

     The output is x = 6 y = -1

    D

     The output is x = 7 y = -1

    E

     Compilation will fail.


    正确答案: E
    解析: 暂无解析

  • 第23题:

    单选题
    class DemoApp{  public static void main(String[] args){  int x = 5; int y = ++x + x++; S ystem.out.println(“y=”+y+”,x=”+x);  }  }  以上程序运行后的输出结果是哪项?()
    A

    y=10,x=5

    B

    y=11,x=6

    C

    y=12,x=7

    D

    y=11,x=7


    正确答案: D
    解析: 暂无解析

  • 第24题:

    单选题
    What is the result?()
    A

     The output is X = 6 y = 0

    B

     The output is x = 7 y = 0

    C

     The output is x = 6 y = -1

    D

     The output is x = 7 y = -1

    E

     Compilation will fail.


    正确答案: D
    解析: 暂无解析