多选题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 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

代码不会完成


参考解析

解析: 暂无解析

相关考题:

以上程序段运行的结果是:______. 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

下面程序创建了一个线程并运行,请填空,使程序完整。public class ThreadTest {public static void main (String[] args) {Hello h=Hew Hello ();【 】t.start ();}}class Hello implements Runnable {int i;public void run () {while(true) {System.out.println("Hello" +i++);if(i==5) break;}}}

( 12 )下列布尔变量定义中,正确并且规范的是A )BOOLEAN canceled = false;B)boolean canceled = false;C)boolean CANCELED = false;D)boolean canceled = FALSE;

下列关于Test类的定义中,正确的是______。A) class Test implements Runnabte{public void run(){}public void someMethod(){}B) class Test implements Rnuuable{public void run();}C) class Test implements Rnuuable{public void someMethod();}D) class Test implements Rnuuable{public void someMethod();{}}A.B.C.D.

( 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

如果一个正整数从高位到低位上的数字依次递减,则称其为降序数(如: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

boolean a=false;boolean b=true;boolean c=(ab)(!b);boolean result=(ab)(!b); boolean result=(ab)(!b); 执行完后,正确的结果是( )。A.c=false;result=falseB.c=true,result=trueC.c=true;result=falseD.c=false;result=true

下面程序段的输出结果为 public class Test { public static void main(String args[]) { boolean a,b,c; a=(3<5); b=(a==true); System.out.println("a="+a+"b="+B); c=(b==false); System.out.println("b="+b+"c="+C); } }A.a=true b=false b=true c=falseB.a=true b=false b=true c=trueC.a=true b=true b=true c=falseD.a=false b=false b=true c=false

下面程序段: boolean a=false; boolean b=true; boolean c=(a||b)(b); boolean result=(a|b)(b); 执行完后,正确的结果是A.c=false;result=falseB.c=true,result=trueC.c=true;result=falseD.c=false;result=true

下列布尔变量定义中,正确并且规范的是A.BOOLEAN canceled=false;B.boolean canceled=false;C.boolean CANCELED=false;D.boolean canceled=FALSE;

下列关于Test类的定义中,正确的是( )。A.class Test implements Runnable{ public void run{} Dublic void someMethod[]{} }B.class Test implements Runnable( puIblic void run; }C.class Test implements Runnable( Dublic void someMethod[]; }D.class Test implements Runnable( public void someMethod{} }

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

下列程序通过实现Runnable接口创建一个线程,选择正确的语句填入程序的横线处。 class MyRun implements Runnable { String str; MyRun(String s) { str = s; } public void run() System.out.println(str); } } public class ex40 { public static void main(String[] args) { String name = "实现阶段Runnable 接口"; MyRun my = new MyRun(name); Thread th = th. start ( ); } }A.new MyRun(my)B.new Thread()C.new Thread(my)D.Thread(my)

下列能够判断Spring容器是否包含ID为proBean的Bean的代码为( )。 A.boolean flag = beanFactory.containsBean("proBean");B.PropertiesBean propertiesBean= (PropertiesBean)beanFactory.getBean("proBean");C.Class classType = beanFactory.getType("proBean");D.PropertiesBean propertiesBean= (PropertiesBean)beanFactory.getBean("proBean", PropertiesBean.class);

( 30 )在程序的下划线处应填入的选项是public class Test _________{public static void main(String args[]){Test t = new Test();Thread tt = new Thread(t);tt.start();}public void run(){for(int i=0;i5;i++){system.out.println( " i= " +i);}}}A ) implements RunnableB ) extends ThreadC ) implements ThreadD ) extends Runnable

现有:  class  Ifs  {  public  static void main (String  []  args)  {      boolean state=false;      int i=2;  if( (++i2)  &&  (state=true))     i++;  if( (++i4)  l l  (state=false))      i++;  System.out .println (i);     }     } 结果为:()     A、  6B、  5C、  4D、编译失败

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.

下列代码正确的是哪项?() A、 public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }B、 public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }C、 public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }D、 public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

Which statements concerning the relationships between the following classes are true?()   class Foo {  int num;   Baz comp = new Baz();   }   class Bar {  boolean flag;   }   class Baz extends Foo {   Bar thing = new Bar();   double limit;   }  A、A Bar is a Baz.B、A Foo has a Bar.C、A Baz is a Foo.D、A Foo is a Baz.E、A Baz has a Bar.

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 Test4 {   public static void main(String [] args) {   boolean x = true;   boolean y = false;   short z = 42;   if((z++ = = 42)  (y = true)) z++;   if((x = false) || (++z = = 45)) z++;   System.out.println("z = " + z);   }   }   结果为:()  A、z = 42B、z = 44C、z = 45D、z = 46

多选题Which statements concerning the relationships between the following classes are true?()   class Foo {  int num;   Baz comp = new Baz();   }   class Bar {  boolean flag;   }   class Baz extends Foo {   Bar thing = new Bar();   double limit;   }AA Bar is a Baz.BA Foo has a Bar.CA Baz is a Foo.DA Foo is a Baz.EA Baz has a Bar.

单选题下列代码正确的是哪项?()A public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }B public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }C public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }D public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

多选题现有:  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代码不会完成

单选题现有:  class  Test4  {  public static void main (String  []  args)  {    boolean X=true;   boolean y=false;    short Z=42;    if((z++==42)  &&  (y=true))z++;    if((x=false)  ||    (++z==45))  z++;    System. out.println(¨z=”+z);     }    }  结果为:()A  Z=42B  z=44C  Z= 45D  z= 46

单选题现有:  interface Animal {       void eat () ;       }       //insert code here       public class HouseCat extends Feline {       public void eat() { }       }  和五个申明  abstract class Feline implements Animal { }  abstract  class  Feline  implements  Animal  {  void eat () ;  }  abstract class Feline implements Animal { public void eat();}  abstract class Feline implements Animal { public void eat() {}  }  abstract class Feline implements Animal { abstract public void eat();} 结果为:()A1B2C3D4