代码输出 1 3 4
代码输出 3 4 1
代码输出 1 2 3 4
代码不会完成
第1题:
( 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 )值都出现一次。
第2题:
如果一个正整数从高位到低位上的数字依次递减,则称其为降序数(如: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=True
B.If i=Len(s)+1 Then flag=True Else flag=False
C.If i=Len(s)-1 Then flag=False Else flag=True
D.If i=Len(s)-1 Then flag=True Else flag=False
第3题:
下面程序段的输出结果为 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=false
B.a=true b=false b=true c=true
C.a=true b=true b=true c=false
D.a=false b=false b=true c=false
第4题:
下列布尔变量定义中,正确并且规范的是
A.BOOLEAN canceled=false;
B.boolean canceled=false;
C.boolean CANCELED=false;
D.boolean canceled=FALSE;
第5题:
下列变量定义不合法的是( )。
A、boolean flag=false;
B、int k=1+'k';
C、char ch="c";
D、float r=1/2;
第6题:
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);
第7题:
现有: class Ifs { public static void main (String [] args) { boolean state=false; int i=2; if( (++i>2) && (state=true)) i++; if( (++i>4) l l (state=false)) i++; System.out .println (i); } } 结果为:()
第8题:
下列代码正确的是哪项?()
第9题:
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 (); } } 以下哪两项是正确的?()
第10题:
A Bar is a Baz.
A Foo has a Bar.
A Baz is a Foo.
A Foo is a Baz.
A Baz has a Bar.
第11题:
代码输出l 3 4
代码输出3 4 1
代码输出l 2 3 4
代码输出1 3 4 2
代码运行完毕
代码不会完成
第12题:
1
2
3
4
第13题:
本题程序中实现了一个“生产者一消费者问题”。生产者产生一个随机数存入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
第14题:
boolean a=false; boolean b=true; boolean c=(a&&b)&&(!b); boolean result=(a&b)&(!b); 执行完后,正确的结果是( )。
A.c=false;result=false
B.c=true,result=true
C.c=true;result=false
D.c=false;result=true
第15题:
下面程序段: boolean a=false; boolean b=true; boolean c=(a||b)&&(b); boolean result=(a|b)&(b); 执行完后,正确的结果是
A.c=false;result=false
B.c=true,result=true
C.c=true;result=false
D.c=false;result=true
第16题:
下列关于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{} }
第17题:
下列程序通过实现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)
第18题:
( 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;i<5;i++){
system.out.println( " i= " +i);
}
}
}
A ) implements Runnable
B ) extends Thread
C ) implements Thread
D ) extends Runnable
第19题:
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?()
第20题:
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; }
第21题:
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); } } 结果为:()
第22题:
public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }
public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }
public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
第23题:
Z=42
z=44
Z= 45
z= 46