网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

class Waiting implements Runnable {  boolean flag = false;  public synchronized void run() {  if (flag) {  flag = false;  System.out.print("1 ");  try { this.wait(); } catch (Exception e) { }  System.out.print("2 ");  }  else {  flag = true;  System.out.print("3 ");  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("4 ");  notify();  }  }  public static void main(String [] args) {  Waiting w = new Waiting();  new Thread(w).start();  new Thread(w).start ();  }  }  以下哪两项是正确的?() 

  • A、代码输出 1 3 4
  • B、代码输出 3 4 1
  • C、代码输出 1 2 3 4
  • D、代码不会完成

参考答案

更多 “ class Waiting implements Runnable {  boolean flag = false;  public synchronized void run() {  if (flag) {  flag = false;  System.out.print("1 ");  try { this.wait(); } catch (Exception e) { }  System.out.print("2 ");  }  else {  flag = true;  System.out.print("3 ");  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("4 ");  notify();  }  }  public static void main(String [] args) {  Waiting w = new Waiting();  new Thread(w).start();  new Thread(w).start ();  }  }  以下哪两项是正确的?() A、代码输出 1 3 4B、代码输出 3 4 1C、代码输出 1 2 3 4D、代码不会完成” 相关考题
考题 以上程序段运行的结果是:______. Dim a(-1 To 5) As Boolean Dim flag As Boolean flag = False Dim i As Integer Dim j As Integer Do Until flag = True For i = -1 To 5 j=j+1 if a(i)= False Then a(i)= True Exit For End If If i = 5 Then flag = True End If Next Loop Print jA.20B.7C.35D.8

考题 ( 18 )阅读下列程序Public class Test implements Runnable{Private int x=0;Private int y=o;boolean flag=true;Public static void main(string[ ] args) {Test r =new Test( );Thead t1=new Thead(r);Thead t2=new Thead(r);t1.start( );t2.start( );}Public void run(){While(flag) {x++;y++;system.out.println( “ ( ” +x_ “ , ” +y+ ” ) ” );if (x=10)flag=false;}}}下列对程序运行结果描述的选项中,正确的是A)每行的( x,y )中,可能有;每一对( x,y )值都出现两次。B)每行的( x,y )中,可能有;每一对( x,y )值仅出现一次。C)每行的( x,y )中,可能有 x=y ;每一对( x,y )值都出现两次。D)每行的( x,y )中,可能有 x=y ;每一对( x,y )值都出现一次。

考题 本题程序中实现了一个“生产者一消费者问题”。生产者产生一个随机数存入DataPool类中,消费者从中取出数据。DataPool类一次只能存放一个数据。请更正题中带下划线的部分。注意:不改变程序的结构,不得增行或删行。class DataPool{private int data;private boolean isFull;public DataPool(){isFull=false;}public synchronized void putData(int d){if(isFull= =true){try{this.notify();}catch(InterruptedException e){}}data=d;isFull=true;System.out.println("生产了一个数据:"+data);this.notify();}public synchronized int getData(){if(isFull= =false){try{this.wait();}catch(InterruptedException e){}}isFull=false;System.out.println("消费了一个数据"+data);this.wait();return this.data;}boolean getIsFull(){return isFull;}}class Producer extends Thread{DataPool pool;public Producer(DataPool pool){this.pool=pool;}public void run(){for(int i=0; i<10; i++){int data=(int) (Math.random()*1000);try{//用于生产数据sleep(data);}catch(InterruptedException e){}pool.putData(data);}}}class Consumer implements Runnable{DataPool pool;public Consumer(DataPool pool){this.pool=pool;}public void run(){for(int i=0; i<10; i++){int data=pool.getData();try{//用于处理数据sleep((int) (Math.random()*1000));}catch(InterruptedException e){}}}}public class advance}public static void main(String[] args){Data Pool pool=new Data Pool();Producer pro=new Producer(pool);Runnable con=new Consumer(pool);Thread conTh=new Thread(con);&n

考题 classWaitingimplementsRunnable{booleanflag=false;publicsynchronizedvoidrun(){if(flag){flag=false;System.out.print(1);try{this.wait();}catch(Exceptione){}System.out.print(2);}else{flag=true;System.out.print(3);try{Thread.sleep(2000);}catch(Exceptione){}System.out.print(4);notify();}}publicstaticvoidmain(String[]args){Waitingw=newWaiting();newThread(w).start();newThread(w).start();}}以下哪两项是正确的?()

考题 public class Test{public static void main(String[]args){intx=5;boolean b1=true;boolean b2=false;if((x==4)!b2)System.out.print(l);System.out.print(2);if((b2=true)b1)System.out.print(3);}}What is the result?()A.2B.3C.12D.23E.123F.Compilation fails.G.An exceptional ist hrown at runtime.

考题 publicclassAlpha1{publicstaticvoidmain(String[]args){booleanflag;inti=0;do{flag=false;System.out.println(i++);flag=i10;continue;}while((flag)?true:false);}}Whatistheresult?() A.000000000B.0123456789C.Compilationfails.D.Thecoderunswithnooutput.E.Thecodeentersaninfiniteloop.F.Anexceptionisthrownatruntime.

考题 如果一个正整数从高位到低位上的数字依次递减,则称其为降序数(如:9632是降序数,而8516则不是降序数)。现编写如下程序,判断输入的正整数是否为降序数。 Private Sub Command1 Click( ) Dim n As Long Dim flag As Boolean n=InputBox("输入一个正整数") S=Trim(Str(n)) For i=2 To Len(s) If Mid(s,i-1,1)Mid(S,i,1)Then Exit For Next i If i=Len(S)Then flag=True Else flag=False If flag Then Print n;"是降序数" Else Print n;"不是降序数" End If End Sub 运行以上程序,发现有错误,需要对给flag变量赋值的If语句进行修改。以下正确的修改是( )。A.If i=Len(s)+1 Then flag=False Else flag=TrueB.If i=Len(s)+1 Then flag=True Else flag=FalseC.If i=Len(s)-1 Then flag=False Else flag=TrueD.If i=Len(s)-1 Then flag=True Else flag=False

考题 下列变量定义不合法的是( )。A、boolean flag=false;B、int k=1+'k';C、char ch="c";D、float r=1/2;

考题 以下程序段运行的结果是______。Dim a(-1 To 5) As BooleanDim flag As Booleanflag = FalseDim i As IntegerDim j As IntegerDo Until flag = True For i=-1 To 5 j=j+1 If a(i)= False Then a(i)= True Exit For End If If i = 5 Then flag = True End If NextLoopPrint jA.20B.7C.35D.8

考题 阅读下列程序: Public class Test implements Runnable{ Private int x=0l Private int y=0; boolean flag=true; Public static void main(string[]args){ Test r=new Test; Thead tl=new Thead(r); Thead t2=new Thead(r); tl.start; t2.start; } Public void run{ While(flag){ x++; y++; system.out.println("("+x-","+y+")"); if(x=10) flag=false; } } } 下列对程序运行结果描述的选项中,正确的是( )。A.每行的(x,y)中,可能有x≠y;每一对(x,y)值都出现两次B.每行的(x,y)中,可能有x≠y;每一对(x,y)值仅出现 一次C.每行的(x,y)中,可能有x=y;每一对(x,y)值都出现两次D.每行的(x,y)中,可能有x=y;每一对(x,y)值都出现

考题 下列选项中,哪个是程序的运行结果class Test{public static void main(String[] args) {int a = 3;int b = 6;System.out.print(a==b);System.out.print(aSystem.out.print(a!=b);System.out.print(a>=b);}} A.false false true falseB.false false true trueC.false true true falseD.true false false true

考题 以下程序段运行的结果是______。 Dim a(-1 To 5)As Boolean Dim flag As Boolean flag=False Dim i As Integer Dim j As Integer Do Until flag=True For i=-1 To 5 j=j+l If a(i)=False Then a(i)=True Exit For End If If i=5 Then flag=True End If Next Loop Print jA.20B.7C.35D.8

考题 现有:  class Waiting implements Runnable  {       boolean flag=false;  public  synchronized void run()  {       if  (flag)  {       flag=false;  System.out.print ("1");  try  {  this.wait();  )  catch  (Exception e)  {  }       System.out.print ("2");       }  else  {       flag=true;  System.out.print ("3");  try{Thread.sleep (2000); } catch(Exception e)  {}      System.out.print ("4");       notify();       }       }  public static void main (String  []  args)  {       Waiting w=new Waiting();       new Thread (w) .start();       new Thread (w) .start();       }       }  以下哪两项是正确的?()    A、代码输出l 3 4B、代码输出3 4 1C、代码输出l 2 3 4D、代码输出1 3 4 2E、代码运行完毕F、代码不会完成

考题 public class Test {  public static void main(String [] args) {  int x =5;  boolean b1 = true;  boolean b2 = false;  if((x==4)  !b2)  System.out.print(”l “);  System.out.print(”2 “);  if ((b2 = true)  b1)  System.out.print(”3 “);  } }  What is the result?() A、 2B、 3C、 1 2D、 2 3E、 1 2 3F、 Compilation fails.G、 Au exceptional is thrown at runtime.

考题 public class Alpha1 {  public static void main( String[] args ) {  boolean flag; int i=0;  do {  flag = false;  System.out.println( i++ );  flag = i  10;  continue;  } while ( (flag)? true:false );  }  }  What is the result?()  A、 000000000B、 0123456789C、 Compilation fails.D、 The code runs with no output.E、 The code enters an infinite loop.F、 An exception is thrown at runtime.

考题 class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");    } catch (Exception e) { }      }  }   和命令行:  java ThreadExcept 1000    哪一个是结果?()  A、 mainB、 编译失败C、 代码运行,但没有输出D、 main java.lang.RuntimeException:exception

考题 During a boot, which of the following procedures is most likely to present a menu that prompts the user to copy a dump?()A、 Set the dump device to /dev/hd6. B、 Run sysdumpdev to set the force copy flag for dump to true. C、 Run sysdumpdev to set the force copy flag for dump to false. D、 Increase space in the /tmp directory. 

考题 public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()  A、 ACB、 BDC、 ACDD、 ABCDE、 Compilation fails.

考题 public class Test{ public static void main(String[]args){ intx=5; boolean b1=true; boolean b2=false; if((x==4)!b2) System.out.print("l"); System.out.print("2"); if((b2=true)b1) System.out.print("3"); } } What is the result?()A、2B、3C、12D、23E、123F、Compilation fails.G、An exceptional ist hrown at runtime.

考题 class Work implements Runnable {  Thread other;   Work(Thread other) { this.other = other; }  public void run() {  try { other.join(); } catch (Exception e) { }  System.out.print("after join ");  } }  class Launch {  public static void main(String [] args) {  new Thread(new Work(Thread.currentThread())).start();  System.out.print("after start ");  } }  结果为:()A、after joinB、after startC、after join after startD、after start after join

考题 public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()  A、 BDB、 BCDC、 BDED、 BCDEE、 ABCDEF、 Compilation fails.

考题 现有:  class Birds {  public static void main (String  []  args)  {   try {  throw new Exception () ;    } catch (Exception e) {   try {   throw new Exception () ;  }  catch  (Exception e2)  {  System.out.print ("inner           "); }   System. out.print ( "middle" ) ;    }  System.out.print ("outer") ;    }    }  结果是()A、 inner outerB、 middle outerC、 inner middle outerD、.编译失败

考题 class Birds {  public static void main(String [] args) {  try {  throw new Exception();  } catch (Exception e) { try {  throw new Exception();  } catch (Exception e2) { System.out.print("inner "); }  System.out.print("middle "); }  System.out.print("outer ");  }  }  结果为:()  A、innerB、inner outerC、middle outerD、inner middle outer

考题 class Order implements Runnable {    public void run ()  {  try { Thread.sleep (2000) ;  } catch (Exception e)    System.out.print("in") ;  public static void main (String [] args)  {    Thread t = new Thread (new Order ()) ;    t.start () ;  System.out.print ("pre ") ;  try { t.join () ;  } catch (Exception e)  { }    System.out.print ("post") ;   可产生哪两项结果?()  A、 pre in postB、 pre inC、 in post preD、 in pre postE、 pre post in

考题 单选题public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()A  BDB  BCDC  BDED  BCDEE  ABCDEF  Compilation fails.

考题 多选题class Waiting implements Runnable {  boolean flag = false;  public synchronized void run() {  if (flag) {  flag = false;  System.out.print("1 ");  try { this.wait(); } catch (Exception e) { }  System.out.print("2 ");  }  else {  flag = true;  System.out.print("3 ");  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("4 ");  notify();  }  }  public static void main(String [] args) {  Waiting w = new Waiting();  new Thread(w).start();  new Thread(w).start ();  }  }  以下哪两项是正确的?()A代码输出 1 3 4B代码输出 3 4 1C代码输出 1 2 3 4D代码不会完成

考题 多选题class Order implements Runnable {  public void run() {  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("in ");  }  public static void main(String [] args) {  Thread t = new Thread(new Order());  t.start();  System.out.print("pre ");  try { t.join(); } catch (Exception e) { }  System.out.print("post ");  } }  可产生哪两项结果?()Ain preBpre inCin pre postDpre in post