更多"请阅读下面程序
public class Exampl"的相关试题:
[单项选择]请阅读下面程序
public class ExampleStringBuffer
public static void main (String[]args)
StringBuffer sb=new StringBuffer("test");
System.out.printIn("buffer="+sb);
System, out.printIn("length="+sb.length( ));
程序运行结果中在“length=”后输出的值是______。
A. 10
B. 4
C. 20
D. 30
[单项选择]阅读下面程序
public class ExampleStringBuffer
public static void main(String[] args)
StringBuffer sb=new StringBuffer("test");
System.out.println("buffer="+sb);
System.out.println("length="+sb.length( ));
程序运行结果中,在“length=”后输出的值是
A. 10
B. 4
C. 20
D. 30
[单项选择]阅读下面程序 public class ExampleStringBuffer { public static void main(String[] args) { StringBuffer sb=new StringBuffer("test"); System.out.println("buffer="+sb); System.out.println("length="+sb.length( )); } } 程序运行结果中,在“length=”后输出的值是
A. 10
B. 4
C. 20
D. 30
[单项选择]请阅读下面程序
public class OperatorsAndExpressions
void residual( )
int i=100.j=30;
float m=563.5f,n=4.0f;
System,out.printIn (i%j);
System, .out.printIn (m%n);
public static void main (String args[])
OperatorsAndExpressions OperAndExp=new OperatorsAndExpressions( );
//取模运算在整数和浮点数中的应用
OperAndExp.residual( );
程序运算结果是______。
A. 10
B. 20
C. 10
D. -20
[单项选择]请阅读下面程序
public class ThreadTest{
public static void main(String args[])throws Ex-
ception{
int i=0;
Hello t=new Hello( );
;
while(true){
System.Out.println("Good Morning"+i++):
if(i= =2&&t.isAlive( )){
System.out.println("Main waiting for Hel-
lo!");
t.join( );//等待t运行结束
}
if(i= =5)break;}
}
}
class Hello extends Thread{
int l;
public void run( ){
while(true)(
System.Out.println("Hell0"+i++);
if(i= =5)break;)))
为使该程序正确执行,下画线处的语句应是( )。
A. t.sleep()
B. t.yield()
C. t.interrupt()
D. t.start()
[单项选择]请阅读下面程序
public class ForLoopStatement
public static void main (String[] args)
int i;j;
for(i=1;i<5;j++)//i循环
for(j=1;j<=i;j++)//j循环
System.out.print(i+"*"+j+"="+i*j+" ");
System.out.printIn( );
程序完成后,i循环和j循环执行的次数分别是______。
A. 4,10
B. 8,9
C. 9,8
D. 10, 10
[单项选择]请阅读下面程序
public class ThreadTest
public static void inain(String args[]) throws Exception
int i=0;
Hello t=new Hello( );
______;
while(true)
System.out.printIn ("Good Morning"+j++);
if(i==2&&LisAlive( ))
System.out.printIn("Main waiting for Hello!");
T.join( );//等待t运行结束
if(i==5)break;
class Hello extends Thread
int i ;
public void run( )
while(true)
System.out.printIn("Hello"+i++);
if(i==5) break;
为使该程序正确执行,下画线处的语句应是______。
A. sleep()
B. yield()
C. interrupt()
D. start()
[单项选择]请阅读下面程序
public class ThreadTest
public static void main(String args[])throws Exception
int i=0:
Hello t=new Hello( );
_________;
while(true)
System.out.println("Good Morning"+i++);
if(i==2&&t.isAlive( ))
System.out.println("Main waiting for Hello!");
t.join( );//等待t运行结束
if(i==5)break;)
class Hello extends Thread
int i;
public void run( )
while(true)
System.out.println("Hello"+i++);
if(i==5)break;
为使该程序正确执行,下画线处的语句应是( )。
A. sleep()
B. yield()
C. interrupt()
D. start()
[填空题]请阅读下面程序
public class Test
public static void main (String[] args)
int i,j;
for (i=1;i<5;i++)
for (j=1;j<=i;j++)
system.out.print (i+"X"+j+"="+i*j+" ");
System.out.println( );
程序执行完后,i循环和j循环执行的次数分别是 【12】 。
[填空题]请阅读下面程序
public class Test {
public static void main (String[] args) {
int i,j;
for (i=1;i<5;i++) {
for (j=1;j<=i;j++)
system.out.print (i+"X"+j+"="+i*j+" ");
System.out.println( );
}
}
}
程序执行完后,i循环和j循环执行的次数分别是 【12】 。
[单项选择]请阅读下面程序
import java.io;
public class TypeTransition
pubic static void main (String args[])
char a=’a’;
int i=100;
long y=456L;
int aa=a+i;
long yy=y-aa;
System.out.print("aa="+aa);
System.out.print("yy ="+yy);
程序运行结果是______。
A. aa=197 yy=259
B. aa=177 yy=259
C. aa=543 yy= 288
D. aa=197 yy=333
[单项选择]请阅读下面程序
import java.io.*;
public class ExceptionCatch
public static void main (String args[])
try
FilelnputStream fis=new FilelnputStream("text");
System.out.printIn ("content oftext isA: ");
catch (FileNotFoundException e)
System.out.printIn (e);
System.out.printIn("message: "+e.getMessge( ));
e.printStackTrace(Sysrem.out);
______
System.out.printIn (e);
为保证程序正确运行,程序中下画线处的语句应是______。
A. catch(FilelnpuStueam fis)
B. printStackTrace()
C. catch(IOException e)
D. System.out.printIn(e)
[单项选择]请阅读下面程序
publicclassExampleStringBuffer
publicstaticvoidmain(String[]args)
StringBuffersb=newStringBuffer("test");
System.out.println("buffer-,"+sb);
System.out.println("longth="+sb.1ength( ));
程序运行结果中在“length”后输出的值是( )。
A. 10
B. 4
C. 20
D. 30
[单项选择]请阅读下面程序
publicclassThreadTest
publicstaticvoidmain(Stringargs[])throwsException
inti=0;
Hellot=newHello( );
______,
while(true)
System.out.println("GoodMoming"+i++);
if(i==2&&t.isAlive( ))
System.out.println("MainwaitingforHello!");
t.join( );//等待t运行结束
if(i==5)break;
classHelloextendsThread
inti;
publicvoidrun( )
while(true)
System.out.println("Hello"+i++);
if(i==5)break;
为使该程序正确执行, 下划线处的语句应是( )。
A. sleep()
B. yield()
C. interrupt()
D. start()
[单项选择]请阅读下面程序 publicclassThreadTest{ publicstaticvoidmain(Stringargs[])throwsException{ inti=0; Hellot=newHello( ); ______, while(true){ System.out.println("GoodMoming"+i++); if(i==2&&t.isAlive( )){ System.out.println("MainwaitingforHello!"); t.join( );//等待t运行结束 } if(i==5)break;} } } classHelloextendsThread{ inti; publicvoidrun( ){ while(true){ System.out.println("Hello"+i++); if(i==5)break;}}} 为使该程序正确执行, 下划线处的语句应是( )。
A. sleep()
B. yield()
C. interrupt()
D. start()
[单项选择]请阅读下面程序,说明该程序创建线程使用的方法是( )。
public class ThreadTest
{
public static void main(String args[])
{
Thread tl=new Thread(new HolloWorld( ));
Thread t2=new Thread(new HolloWorld( ));
tl.start( );
t2.Start( );
}
}
class HolloWorld implements Runnable
{
int i;
public void run( )
{
while(true)
{
System.out.println("HolloWorld"+i++);
if(i= =5)break;
}
}
}
A. 继承Thread类
B. 实现Runnable接口
C. tl.start()
D. t2.start()