publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i<4;i++){current=x;System.out.print(current+,);x=current+2;}}}publicstaticvoidmain(String[]args){newThreads1().go();}publicvoidgo(){Runnabler1=newRunne

题目

publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i<4;i++){current=x;System.out.print(current+,);x=current+2;}}}publicstaticvoidmain(String[]args){newThreads1().go();}publicvoidgo(){Runnabler1=newRunner();newThread(r1).start();newThread(r1).start();}}Whichtwoarepossibleresults?()

A.0,2,4,4,6,8,10,6,

B.0,2,4,6,8,10,2,4,

C.0,2,4,6,8,10,12,14,

D.0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,

E.0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,


相似考题
更多“publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i4;i++){current=x;System.out.print(current+,);x=current+2;}}}publicstaticvoidmain(String[]args){newThreads1().go();}publicvoidgo(){Runnabler1=newRunner”相关问题
  • 第1题:

    classRectangle{publicstaticvoidmain(String[]args){int[]x={1,2,3};x[1]=(x[1]〉1)?x[2]:0;System.out.println(x[1]);}}结果为:()

    A.0

    B.1

    C.2

    D.3


    参考答案:D

  • 第2题:

    classPasser{staticfinalintx=5;publicstaticvoidmain(String[]args){newPasser().go(x);System.out.print(x);}voidgo(intx){System.out.print(++x);}}结果是什么?()

    A.55

    B.56

    C.65

    D.66


    参考答案:C

  • 第3题:

    程序:classTestApp{publicstaticvoidmain(String[]args){for(inti=0;i<10;i++){if(i==3)break;System.out.print(i);}}}程序运行后的输出是哪项?()

    A.0123

    B.012

    C.0123456789

    D.012456789


    参考答案:B

  • 第4题:

    publicclassTestFive{privateintx;publicvoidfoo(){intcurrent=x;x=current+1;}publicvoidgo(){for(inti=0;i<5;i++){newThread(){publicvoidrun(){foo();System.out.print(x+,);}}.start();}}}Whichtwochanges,takentogether,wouldguaranteetheoutput:1,2,3,4,5,?()

    A.Movetheline12printstatementintothefoo()method.

    B.Changeline7topublicsynchronizedvoidgo(){.

    C.Changethevariabledeclarationonline3toprivatevolatileintx;.

    D.Wrapthecodeinsidethefoo()methodwithasynchronized(this)block.

    E.Wraptheforloopcodeinsidethego()methodwithasynchronizedblocksynchronized(this){//forloopcodehere}.


    参考答案:A, D

  • 第5题:

    publicclassThreads4{publicstaticvoidmain(String[]args){newThreads4().go();}publicvoidgo(){Runnabler=newRunnable(){publicvoidrun(){System.out.print(”foo”);}};Threadt=newThread(r);t.start();t.start();}}Whatistheresult?()

    A.Compilationfails.

    B.Anexceptionisthrownatruntime.

    C.Thecodeexecutesnormallyandprints?foo”.

    D.Thecodeexecutesnormally,butnothingisprinted.


    参考答案:B

  • 第6题:

    publicclassAlpha{privatestaticCharacter()ids;publicstaticvoidmain(String[]args){ids=newCharacter[args.length];for(inti=0;iids[i]=newCharacter(args[i]);System.out.print(ids[i]);}}}Whatiscorrect?()

    A.Compilationfails.

    B.Thecoderunswithnooutput.

    C.Anexceptionisthrownatruntime.

    D.Thecoderuns,outputingaconcatenatedlistoftheargumentspassedtotheprogram.


    参考答案:A
    Compilationfails.Line2:ReturnTyperequired.

  • 第7题:

    publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x>0):“assertionfailed”;System.out.println(“finished”);}}Whatistheresult?()

    A.finished

    B.Compilationfails.

    C.AnAssertionErroristhrown.

    D.AnAssertionErroristhrownandfinishedisoutput.


    参考答案:A

    Thisquestionisabittrickybecauseitlacksthefollowinginformation:Itshouldincludeastatementthatsayswhetherornotassertionsareenabled.Iftheyareindeedenabled,the
    correctionanswerisC.butiftheyarenot,thecorrectanswerisA.Assertionsarenotenabledbydefaultsoifthequestionisnotchanged,themostlogicalanswerisA.

  • 第8题:

    class TestApp{   public static void main (String[ ] args){   for(int i=0;i<10;i++){   if(i==3)   break;   System.out.print (i);  }  }  }   程序运行后的输出是哪项?()  

    • A、0123
    • B、012
    • C、0123456789
    • D、012456789

    正确答案:B

  • 第9题:

    下列程序的功能是:输出200以内的所有素数。请填空。 usingSystem; classProgram { publicboolsushu(intx) { k=Convert.ToInt32(Math.Sqrt(x)) for(i=2;i<=k;i++) if(x%i==0)returnfalse; (break); }publicstaticvoidMain(string[]args) { inti,j;for(i=3;i<=200;i=i+2) { if(())Console.WriteLine(“{0}”,i);


    正确答案:if %2=1

  • 第10题:

    public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i<4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()

    • A、 0, 2, 4, 4, 6, 8, 10, 6,
    • B、 0, 2, 4, 6, 8, 10, 2, 4,
    • C、 0, 2, 4, 6, 8, 10, 12, 14,
    • D、 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
    • E、 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

    正确答案:A,C

  • 第11题:

    填空题
    下列程序的运行结果是() classProgramx=0,y=-1; { publicstaticvoidMain(string[]args) { int i=0,s=1; do{s/=s+1;i++; } while(i<=10); Console.WriteLine(“i={0},s={1}”,i,s);

    正确答案: i=11,s=12
    解析: 暂无解析

  • 第12题:

    填空题
    下列程序的功能是:输出100以内能被3整除且个位数为6的所有整数。请填空。 usingSystem; classProgram{ publicstaticvoidMain(string[]args) { int i,j; for(()); (); i++) { j=i*10+6; if((j%3==0))continue; Console.WriteLine(“{0}”,j);

    正确答案: i=100
    解析: 暂无解析

  • 第13题:

    classFoo{publicstaticvoidmain(String[]args){intx=0;inty=4;for(intz=0;z〈3;z++,x++){if(x〉1&++y〈10)y++;}System.out.println(y);}}结果是什么?()

    A.6

    B.7

    C.8

    D.10


    参考答案:C

  • 第14题:

    程序:classTestApp{publicstaticvoidmain()String[]args){for(inti=0;i<10;i++){if(i==3)break;当循环到3时,自动跳出System.out.print(i);}}}程序运行后的输出是哪项?()

    A.0123

    B.012

    C.0123456789

    D.012456789


    参考答案:B

  • 第15题:

    现有:classPasserfstaticfinalintX=5;publicstaticvoidmain(String[]args){newPasser().go(x);System.out.print(x);}voidgo(intx){System.out.print(x++);}结果是什么?()

    A.55

    B.56

    C.65

    D.66


    参考答案:A

  • 第16题:

    publicclassTestOneimplementsRunnable{publicstaticvoidmain(String[]args)throwsException{Threadt=newThread(newTestOne());t.start();System.out.print(”Started”);t.join();System.out.print(”Complete”);}publicvoidrun(){for(inti=0;i<4;i++){System.out.print(i);}}}Whatcanbearesult?()

    A.Compilationfails.

    B.Anexceptionisthrownatruntime.

    C.Thecodeexecutesandprints“StartedComplete”.

    D.Thecodeexecutesandprints“StartedComplete0123”.

    E.Thecodeexecutesandprints“Started0l23Complete”.


    参考答案:E

  • 第17题:

    publicclassTest{privatestaticint[]x;publicstaticvoidmain(String[]args){System.out.println(x[0]);}}Whatistheresult?()

    A.0

    B.null

    C.Compilationfails.

    D.ANullPointerExceptionisthrownatruntime.

    E.AnArrayIndexOutOfBoundsExceptionisthrownatruntime.


    参考答案:D

  • 第18题:

    publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x>0)?assertionfailed”:assertionpassed”;System.out.println(Finished”);}}Whatistheresult?()

    A.finished

    B.Compilationfails.

    C.AnAssertionErroristhrownandfinishedisoutput.

    D.AnAssertionErroristhrownwiththemessage“assertionfailed”.

    E.AnAssertionErroristhrownwiththemessage“assertionpassed”.


    参考答案:B

  • 第19题:

    本题定义了一个长度为l0的boolean型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值 为false,否则为true。 public class javal{ pubhc static void main(String[]args){ boolean b[]= ; for(int i=0;i<10;i++){ if( ) b[i]=false; else ; } for(int i=0;i<10;i++) System.Out.print("bE"+i+"]="+b[i]+","); } }


    正确答案:
    第1处:new boolean[10]
    第2处:i%2 1=0
    第3处:b[i]=true
    【解析】第1处定义了一个长度为10的boolean型数组;第2处判断数组元素下标是否为奇数。第3处不为奇数的情况下数组元素值设为true。

  • 第20题:

    下列程序的功能是:输出100以内能被3整除且个位数为6的所有整数。请填空。 usingSystem; classProgram{ publicstaticvoidMain(string[]args) { int i,j; for(()); (); i++) { j=i*10+6; if((j%3==0))continue; Console.WriteLine(“{0}”,j);


    正确答案:i=100

  • 第21题:

    下列程序的运行结果是() classProgramx=0,y=-1; { publicstaticvoidMain(string[]args) { int i=0,s=1; do{s/=s+1;i++; } while(i<=10); Console.WriteLine(“i={0},s={1}”,i,s);


    正确答案:i=11,s=12

  • 第22题:

    public class TestFive {  private int x;  public void foo() {  int current = x;  x = current + 1;  }  public void go() {  for(int i=0;i<5;i++) {  new Thread() {  public void run() {  foo();  System.out.print(x + “, “);  } }.start();  }}}  Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()

    • A、 Move the line 12 print statement into the foo() method.
    • B、 Change line 7 to public synchronized void go() {.
    • C、 Change the variable declaration on line 3 to private volatile int x;.
    • D、 Wrap the code inside the foo() method with a synchronized( this ) block.
    • E、 Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.

    正确答案:A,D

  • 第23题:

    多选题
    public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i<4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()
    A

    0, 2, 4, 4, 6, 8, 10, 6,

    B

    0, 2, 4, 6, 8, 10, 2, 4,

    C

    0, 2, 4, 6, 8, 10, 12, 14,

    D

    0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,

    E

    0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,


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