try { int x = 0; int y = 5 / x; } catch (Exception e) { System.out.println(“Exception”); } catch (ArithmeticException ae) { System.out.println(“Arithmetic Exception”); } System.out.println(“finished”); What is the result?()
第1题:
本题程序中实现了一个“生产者一消费者问题”。生产者产生一个随机数存入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
第2题:
下面程序的输出结果是 public class Test{ public static void main(String[] args){ int[]array={2,4,6,8,10}; int size=6; int result=-1: try{ for(int i=0;i<size&&result==-1;i++) if(array[i]==20)result=i; }catch(ArithmeticException e){ System.out.println("Catch---1"); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("Catch---2"); }catch(Exception e){ System.out.println("Catch---3"); } } }
A.Catch---1
B.Catch一--2
C.Catch---3
D.以下都不对
第3题:
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【函数2.1】
void sort(char *s,int num)
{int i,j--num;
char t;
while(j-->1)
for(i=0;i<j;i++)
if(s[i]>s[i+1])
{t=s[i];
s[i]=s[i+1];
s[i+1]=t;
}
void main()
{char *s="CEAedea";
sort(s,5);
printf("%s",s);
}
上述程序的结果是(1)
【函数2.2】
void main()
{ union {int ig[6];
Char s[12];} try;
try. ig[0]=0x4542; try.ig[1]=0x2049;
try. ig[2]=0x494a; try.ig[3]=0x474e;
try. ig[4]=0x0a21; try.ig[5]=0x0000;
pintf("%s",try, s);
}
上述程序的结果是(2)
【函数2.3】
void main()
{ char *letter[5]= { "ab","efgh","ijk","nmop","st"};
char **p;
int i;
p=letter;
for(i=0;i<4;i++) .
printf("%s",p[i]);
}
上述程序的结果是(3)
【函数2.4】
main()
{int i=4,j=6,k=8,*p=&I,*q=&j,*r=&k;
int x,y,z;
x=p==&i;
y=3*-*p/(*q)+7;
z=*(r=&k)=*p**q;
printf("x=%d,y=%d,z=%d",x,y,z);
}
上述程序的结果是(4)
【函数2.5】
int a[]={5,4,3,2,1 };
void main()
{int i;
int f=a[0];
int x=2;
for(i=0;i<5;i++)
f+=f*x+a[i];
printf("%d",f);
}
上述程序的结果是(5)
第4题:
下列程序的输出结果是( )。 Public class Test{ Public static void main(String[]args){ int[]array=(2,4,6,8,10); int size=6; int result=-l: try{ for(int i=0;i<sizeresult= =-1:) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch---1"); } catch(ArraylndexOutOfBoundsException e){ System.out.println("Catch---2"): } catch(Exception e){ System.out.println("Catch---3"): } }
A.Catch---1
B.Catch---2
C.Catch---3
D.以上都不对
第5题:
She’s going to () that new dress.
第6题:
研究下面的Java代码: public class testException{ public static void main(String args[]){ int a[]={0,1,2,3,4}; int sum=0; try{ for(int i=1;i<6;i++) sum=sum+a[i]; System.out.println("sum="+sum); } catch(ArrayIndexOutOfBoundsException ){ System.out.println("数组越界"); } finally{ System.out.println("程序结束");} } } 输出结果将是()。
第7题:
public class TestApp{ public int mymethod(){ try{ int i = 0; int j = 1 / i; System.out.println(“1”); }finally{ System.out.print(“4”); } return 1; } } 上述程序运行后的输出是哪项?()
第8题:
4
14
41
以上都不对
第9题:
42
NFExc
42NFExc
编译失败
第10题:
Add a COMMIT TRANSACTION command to the CATCH block.
Remove the COMMIT TRANSACTION command from the TRY block.
Add a ROLLBACK TRANSACTION command to the CATCH block.
Add a ROLLBACK TRANSACTION command to the TRY block.
第11题:
finished
Exception
Compilation fails.
Arithmetic Exception
第12题:
第13题:
阅读下面程序 1 public class Try extends Thread{ 2 public static void main(String args[]){ 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j){ 8 int i=0; 9 while(i<5){ 10 System.out.println(“祝你成功!”); 11 i++; 12 } 13 } 14 } 该程序要求打印5行“祝你成功!”,必须改正程序中的某行代码,程序才能完成。选择正确的修改是
A.将第1行的extends Thread改为implements Runnable
B.将第3行的new Try()改为new Thread()
C.将第4行t.start()改为start(t)
D.将第7行的public void run(int j)改为public void run()
第14题:
设有结构体类型定义: struct try { int one; float two; }*str;若要动态开辟一个结构单元,使指针str指向其首地址,正确的语句是______。
A.str=(try*)malloc(sizeof(try));
B.*str=(struct try*)malloc(sizeof(struct try));
C.str=(strucy try*)malloc(sizeof(struct try));
D.str=(struc try)malloc(sizeof(struct try));
第15题:
以下程序执行后的输出结果是 #include <iostream> using namespace std; void try(int,int,int,int); int main () { int x,y,z,r; x =1 ; y = 2; try(x,y,z,r); cout<<r<<endl; return 0; } void try(int x,int y,int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }
A.18
B.9
C.10
D.不确定
第16题:
以下程序执行后的输出结果是 #include<iostream>. using namespace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }
A.18
B.9
C.10
D.不确定
第17题:
对于下列代码段,执行后输出结果是()。 int n,m; int[] a=new int[5]; n=10; m=10; try{ for(inti=0;i<=a.Length;i++); a[i]=i; n=1/(n-m); } catch(DivideByZeroExceptione1){ Console.WriteLine(“产生零除异常!”); } catch(IndexOutOfRangeExceptione2) { Console.WriteLine(“产生数组访问越界异常!”); }
第18题:
public class TestApp{ public static void main(String[] args){ try{ int i = 0; int j = 1 / i; System.out.println(“1”); } catch(Exception e){ System.out.print(“3”); } finally{ System.out.print(“4”); } } } 上述程序运行后的输出是哪项?()
第19题:
下面关于try、catch和finally语句块的组合使用,正确的是()
第20题:
42Exc
Exc
42
编译失败
第21题:
10 数组越界 程序结束
10 程序结束
数组越界 程序结束
程序结束
第22题:
Thread.sleep(1);
Thread.sleep(100);
Thread.sleep(1000);
try{ Thread.sleep(1); ) catch (Exception e) { }
try{Thread.sleep(100); ) catch (Exception e) { }
try{Thread.sleep(1000); ) catch (Exception e) { }
第23题:
3
2
231
32