网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
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();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, ” 相关考题
考题
下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int x=0; for(int i=1;i<=4;i++) { x=4; for(int j=1;j<=3;j++) { x=3; for(int k=1;k<=2;k++) { x-x+6; } } } System.out.println(x); } }A.7B.15C.157D.538
考题
请选出以下程序的输出结果#includestdio.hmain(){ int a[]={1,2,3,4},i;int x=0;for(i=0;i4;i++){ sub(a,x);printf("%d",x);}printf("\n");}sub(s,y)int *s,y;{ static int t=3;y=s[t];t--; }A.1 2 3 4B.4 3 2 1C.0 0 0 0D.4 4 4 4
考题
classThreadExceptimplementsRunnable{publicvoidrun(){thrownewRuntimeException(exception);}publicstaticvoidmain(String[]args){newThread(newThreadExcept()).start();try{intx=Integer.parseInt(args[0]);Thread.sleep(x);System.out.print(main);}catch(Exceptione){}}}和命令行:javaThreadExcept1000哪一个是结果?()A.mainB.编译失败C.代码运行,但没有输出D.mainjava.lang.RuntimeException:exception
考题
classTestApp{publicstaticvoidmain(String[]args){for(inti=0;i10;i++){if(i==3)break;System.out.print(i);}}}程序运行后的输出是哪项?()
A.0123B.012C.0123456789D.012456789
考题
classRectangle{publicstaticvoidmain(String[]args){int[]x={1,2,3};x[1]=(x[1]〉1)?x[2]:0;System.out.println(x[1]);}}结果为:()
A.0B.1C.2D.3
考题
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.6B.7C.8D.10
考题
classPasser{staticfinalintx=5;publicstaticvoidmain(String[]args){newPasser().go(x);System.out.print(x);}voidgo(intx){System.out.print(++x);}}结果是什么?()
A.55B.56C.65D.66
考题
程序:classTestApp{publicstaticvoidmain()String[]args){for(inti=0;i10;i++){if(i==3)break;当循环到3时,自动跳出System.out.print(i);}}}程序运行后的输出是哪项?()
A.0123B.012C.0123456789D.012456789
考题
程序:classTestApp{publicstaticvoidmain(String[]args){for(inti=0;i10;i++){if(i==3)break;System.out.print(i);}}}程序运行后的输出是哪项?()
A.0123B.012C.0123456789D.012456789
考题
现有:classPasserfstaticfinalintX=5;publicstaticvoidmain(String[]args){newPasser().go(x);System.out.print(x);}voidgo(intx){System.out.print(x++);}结果是什么?()
A.55B.56C.65D.66
考题
publicclassTestFive{privateintx;publicvoidfoo(){intcurrent=x;x=current+1;}publicvoidgo(){for(inti=0;i5;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}.
考题
publicclassTestOneimplementsRunnable{publicstaticvoidmain(String[]args)throwsException{Threadt=newThread(newTestOne());t.start();System.out.print(”Started”);t.join();System.out.print(”Complete”);}publicvoidrun(){for(inti=0;i4;i++){System.out.print(i);}}}Whatcanbearesult?()A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thecodeexecutesandprints“StartedComplete”.D.Thecodeexecutesandprints“StartedComplete0123”.E.Thecodeexecutesandprints“Started0l23Complete”.
考题
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.
考题
publicclassTest{privatestaticint[]x;publicstaticvoidmain(String[]args){System.out.println(x[0]);}}Whatistheresult?()
A.0B.nullC.Compilationfails.D.ANullPointerExceptionisthrownatruntime.E.AnArrayIndexOutOfBoundsExceptionisthrownatruntime.
考题
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.
考题
publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x0)?assertionfailed”:assertionpassed”;System.out.println(Finished”);}}Whatistheresult?()
A.finishedB.Compilationfails.C.AnAssertionErroristhrownandfinishedisoutput.D.AnAssertionErroristhrownwiththemessage“assertionfailed”.E.AnAssertionErroristhrownwiththemessage“assertionpassed”.
考题
publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x>0):“assertionfailed”;System.out.println(“finished”);}}Whatistheresult?()
A.finishedB.Compilationfails.C.AnAssertionErroristhrown.D.AnAssertionErroristhrownandfinishedisoutput.
考题
本题定义了一个长度为l0的boolean型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值 为false,否则为true。 public class javal{ pubhc static void main(String[]args){ boolean b[]= ; for(int i=0;i10;i++){ if( ) b[i]=false; else ; } for(int i=0;i10;i++) System.Out.print("bE"+i+"]="+b[i]+","); } }
考题
class TestApp{ public static void main (String[ ] args){ for(int i=0;i10;i++){ if(i==3) break; System.out.print (i); } } } 程序运行后的输出是哪项?() A、0123B、012C、0123456789D、012456789
考题
下列程序的功能是:输出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);
考题
下列程序的功能是:输出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);
考题
下列程序的运行结果是() 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);
考题
public class Threads 1 { intx=0; public class Runner implements Runnable { public void run() { int current = 0; for(int=i=0;i4;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,
考题
public class TestFive { private int x; public void foo() { int current = x; x = current + 1; } public void go() { for(int i=0;i5;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 }.
考题
填空题下列程序的运行结果是() 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);
考题
多选题public class Threads 1 { intx=0; public class Runner implements Runnable { public void run() { int current = 0; for(int=i=0;i4;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?()A0, 2, 4, 4, 6, 8, 10, 6,B0, 2, 4, 6, 8, 10, 2, 4,C0, 2, 4, 6, 8, 10, 12, 14,D0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,E0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
考题
填空题下列程序的功能是:输出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);
热门标签
最新试卷