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?()  A、 finishedB、 Except

题目

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?()  

  • A、 finished
  • B、 Exception
  • C、 Compilation fails.
  • D、 Arithmetic Exception

相似考题
参考答案和解析
正确答案:D
更多“try {  int x&ens”相关问题
  • 第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


    正确答案:this.wait() this.notify() thread.sleep((int)(Math.random()*1000))
    this.wait() this.notify() thread.sleep((int)(Math.random()*1000)) 解析:本题考查知识点:多线程同步与互斥、线程的概念和实现方法。解题思路:Data Pool是一个用来存放数据的缓冲池,其中可以存放一个血型数据,变量isFull作为标志量,标志该缓冲池中是否有数据。Put Data()方法负责向Data Pool中存放数据,本方法调用成功,缓冲池中就存入了数据,getData()方法负责从DataPool中获得数据,本方法调用成功,缓冲池就为空。Producer类负责产生随机数据,然后将数据存放到DataPool中。Consumer类负责才能够从DataPool中取出数据。Producer和Consumer共享同一个Data Pool对象。当某个线程进入synchronized块后,共享的数据并不一定能满足该线程的需要,这样线程就需要等待其他线程修改共享数据,直到满足需要以后才继续执行,但是当前线程必须释放锁以使得其他线程可以运行。wait()和notify()方法是实现线程之间通信的两个方法。wait()用来释放线程拥有的锁,使线程进入等待队列;notify()用来唤醒等待队列中的线程,并把它加入到申请锁的队列。本题中生产者在DataPool有数据的情况下需要进入等待消费者取出数据,所以需要调用wait()方法,因此第1个下划线的地方应该改为this.wait()。消费者线程在取出数据以后,必须通知生产者线程DataPool中已经没有数据了,因此第2个下划线的地方改为this.notify()。第3个下划线的地方,考查常用的线程类的使用。Runnable接口的目的是使任何类都可以为线程提供线程体,但它本身并不是线程,所以并不能直接调用Thread类的方法,需要改为 thread.sleep。

  • 第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.以下都不对


    正确答案:B
    解析:ArithmeticException是当出现异常的运算条件时,抛出此异常。例如,一个整数“除以零”时,是抛出此类的一个实例;ArrayIndexOutOfBoundsException是用非法索引访问数组时抛出的异常。如果索引为负或大于等于数组大小,则该索引为非法索引。本程序中,数组大小为5个元素,数组下标为0~4,而循环为0~5,数组越界,所以会捕获ArrayIndexOutOfBoundsException。

  • 第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)


    正确答案:(1)ACEdeea (2) BEI JING! (3) abefghijkmnop (4) x=1y=5z=24 (5) 129
    (1)ACEdeea (2) BEI JING! (3) abefghijkmnop (4) x=1,y=5,z=24 (5) 129

  • 第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.以上都不对


    正确答案:B
    B。【解析】本题考查了数组及for循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。

  • 第5题:

    She’s going to () that new dress.

    • A、try out
    • B、try on
    • C、try for

    正确答案:B

  • 第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("程序结束");}  } }  输出结果将是()。       

    • A、10  数组越界  程序结束
    • B、10   程序结束
    • C、数组越界  程序结束
    • D、程序结束

    正确答案:C

  • 第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;  }  }   上述程序运行后的输出是哪项?() 

    • A、 4
    • B、 14
    • C、 41
    • D、 以上都不对

    正确答案:A

  • 第8题:

    单选题
    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;   } }  上述程序运行后的输出是哪项?()
    A

     4

    B

     14

    C

     41

    D

     以上都不对


    正确答案: D
    解析: 暂无解析

  • 第9题:

    单选题
    class Parser extends Utils {  public static void main (String [] args) {  try { System.out.print(new Parser().getInt("42"));  } catch (NumberFormatException n) {  System.out.println("NFExc "); }  }  int getInt(String arg) throws NumberFormatException {  return Integer.parseInt(arg);  }  }  class Utils {  int getInt(String arg) { return 42; }  }  结果为:()
    A

    42

    B

    NFExc

    C

    42NFExc

    D

    编译失败


    正确答案: D
    解析: 暂无解析

  • 第10题:

    单选题
    You are creating a stored procedure that will delete data from the Contact table in a SQL Server 2005 database. The stored procedure includes the following Transact-SQL statement to handle any errors that occur. BEGIN TRY   BEGIN TRANSACTION   DELETE FROM Person.Contact WHERE ContactID = @ContactID COMMIT TRANSACTION END TRY   BEGIN CATCH   DECLARE @ErrorMessage nvarchar(2000) DECLARE @ErrorSeverity int DECLARE @ErrorState int SELECT @ErrorMessage = ERROR MESSAGE(),@ErrorSeverity=ERROR SEVERITY(),@ErrorState = ERROR STATE() RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) END CATCH;      You test the stored procedure and discover that it leaves open transactions. You need to modify the stored procedure so that it properly handles the open transactions. What should you do?()
    A

    Add a COMMIT TRANSACTION command to the CATCH block.

    B

    Remove the COMMIT TRANSACTION command from the TRY block.

    C

    Add a ROLLBACK TRANSACTION command to the CATCH block.

    D

    Add a ROLLBACK TRANSACTION command to the TRY block.


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    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?()
    A

     finished

    B

     Exception

    C

     Compilation fails.

    D

     Arithmetic Exception


    正确答案: A
    解析: The correct answer to this question is D. When an int value is divided by zero, a runtime exception occurs. There are no compilation errors. 

  • 第12题:

    问答题
    对于下列代码段,执行后输出结果是()。 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(“产生数组访问越界异常!”); }

    正确答案: 输出“产生数组访问越界异常!
    解析: 暂无解析

  • 第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()


    正确答案:D
    解析:本题考查线程的创建。Java语言中提供两种创建线程的方法,一种是通过实现Runnable接口来创建线程,另一种是通过继承Thread类创建线程。显然,题目中的程序是使用第二种方法来创建线程。Thread类中定义了run()方法,所以通过继承 Thread类来创建线程时还要重写Thread类中的run()方法。而run()方法的定义如下: public void run(){ }
    题目中的代码比较简单,就是创建了一个线程,这个线程完成的操作就是打印5行“祝你成功”。仔细阅读程序,不难发现第7行有错。在run()方法的定义中是没有参数的,而题目程序中的run方法却带有一个参数。因此,要把第7行的代码改为“public void run()”。因此,本题的正确答案是D。

  • 第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));


    正确答案:C
    解析:由于在ANSIC中malloc函数返回的地址为void,故在调用函数时,必须利用强制类型转换将其转换成所需的类型。

  • 第15题:

    以下程序执行后的输出结果是include using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #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.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在c++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第16题:

    以下程序执行后的输出结果是include.using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #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.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第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”);   }   }   }   上述程序运行后的输出是哪项?() 

    • A、 4
    • B、 34
    • C、 43
    • D、 14

    正确答案:B

  • 第19题:

    下面关于try、catch和finally语句块的组合使用,正确的是()

    • A、try{,}
    • B、try{,}finally{,}
    • C、try{,}catch{,}finally{,}
    • D、try{,}catch{,}catch{,}

    正确答案:B,C,D

  • 第20题:

    单选题
    现有  class Parser extends Utils {  public static void main (String  []  args)  {  try  {  System.out.print (new Parser () .getlnt ("42"))       }  catch (Exception e) {  System.out.println ("Exc") ;  }      }  int getlnt (String arg)  throws Exception  {     return Integer.parselnt (arg) ;      }      }  class Utils {  int getlnt ()  {  return 42;  }     }  结果是什么?()
    A

     42Exc

    B

     Exc

    C

     42

    D

    编译失败


    正确答案: C
    解析: 暂无解析

  • 第21题:

    单选题
    研究下面的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("程序结束");}  } }  输出结果将是()。
    A

    10  数组越界  程序结束

    B

    10   程序结束

    C

    数组越界  程序结束

    D

    程序结束


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    现有:  5.  class Order2 implements Runnable  {     6.    public void run()  {     7. for (int x- o;  x<4;  x++)  {  8. try{Thread.sleep(100);  )catch  (Exception e)  {  }     9.    System.out.print("r");     10.    }  }  11.    public static void main(string  []  args)  {     12.    Thread t=new Thread(new order2());     13.    t.start();  14.    for(int x=0;  x<4;  x++)  {     15.    //insert code here     16.    System.out.print("m");     17.  }  }  }  哪一个插入到第15行,最有可能产生输出 rmrmrmrm?()
    A

      Thread.sleep(1);

    B

      Thread.sleep(100);

    C

      Thread.sleep(1000);

    D

      try{  Thread.sleep(1);  )  catch  (Exception e)  {  }

    E

      try{Thread.sleep(100);  )  catch  (Exception  e)  {  }

    F

      try{Thread.sleep(1000);  )  catch  (Exception  e)  { }


    正确答案: F
    解析: 暂无解析

  • 第23题:

    单选题
    public class TestApp{  public static void main(String[] args){       try{  int i = 0;           int j = 1 / i;           String myname=null;            if(myname.length()>2)              System.out.print(“1”);        }catch(NullPointerException e){  System.out.print(“2”);       }  catch(Exception e){  System.out.print(“3”);       }   } }  上述程序运行后的输出是哪项?()
    A

     3

    B

     2

    C

     231

    D

     32


    正确答案: C
    解析: 暂无解析