4、下面程序的运行结果是() public class Demo { public static void main(String[] args) { try { System.out.println(10 / 0); System.out.println("除法正常运行"); } catch (ArithmeticException e) { System.out.println("除数不能为0"); } } }A.编译失败B.编译通过,没有结果输出C.输出:除法正常运行D.输出:除数不能为0

题目

4、下面程序的运行结果是() public class Demo { public static void main(String[] args) { try { System.out.println(10 / 0); System.out.println("除法正常运行"); } catch (ArithmeticException e) { System.out.println("除数不能为0"); } } }

A.编译失败

B.编译通过,没有结果输出

C.输出:除法正常运行

D.输出:除数不能为0


相似考题
更多“4、下面程序的运行结果是() public class Demo { public static void main(String[] args) { try { System.out.println(10 / 0); System.out.println("除法正常运行"); } catch (ArithmeticException e) { System.out.println("除数不能为0"); } } }”相关问题
  • 第1题:

    下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { for ( int a=0;a<10;a++) { if (a==5) break; System.out.println(A); } } }

    A.01234

    B.6789

    C.012346789

    D.5


    正确答案:A
    解析:题目中输出语句位于循环体内,而在if语句外,所以a5时执行输出语句。当a=5时,退出循环,结束程序的执行。

  • 第2题:

    下列程序的执行结果是 public class Testbb { public static void main(String args[ ]) { System.out.println(5/2.5); } }

    A.0

    B.2

    C.2

    D.2


    正确答案:C
    解析:如果表达式中有不同的数据类型,则寻找自动转换优先级最高的一个,其他数值全部转换成这种数据类型,当然表达式的值也是这个数据类型。

  • 第3题:

    下列程序的输出结果是______。 public class ex21 { public static void main(String[] args) { int n=4; while(--n>0){ } System.out.println(n); } }

    A.0

    B.-1

    C.1

    D.4


    正确答案:A

  • 第4题:

    下面程序的输出结果是 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。

  • 第5题:

    以下程序运行后输出的结果是______。

    public class exl7

    {

    public static void main(String args [])

    {

    int a = 0;

    for(int j = 1; j <= 20; j++)

    if(j%5 != 0)

    a = a + j;

    System.out.println (a);


    正确答案:160
    160

  • 第6题:

    下列程序的输出结果是( )。 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。

  • 第7题:

    下列程序创建了一个线程并运行,请在下划线处填入正确代码。

    public class Try extends Thread{

    public static void main(String args[]){

    Threadt=new Try();

    【 】;

    }

    public void run(){

    System.out.println(“Try!”);

    }

    }


    正确答案:i
    i

  • 第8题:

    研究下面的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

  • 第9题:

    public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finally
    • B、 exception finished
    • C、 finally exception finished
    • D、 Compilation fails.

    正确答案:C

  • 第10题:

    现有:      class TestA  {  public void start()  {  System.out.println("TestA");  }     }  public class TestB extends TestA  {  public void start()  {  System.out.println("TestB");  }     public static void main (string[]  args)  (     ((TestA)new TestB()).start();     )     }  运行结果是哪项?()     

    • A、  TeStA
    • B、  TeStB
    • C、编译失败
    • D、运行时抛出异常

    正确答案:B

  • 第11题:

    单选题
    Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?()   CODE FRAGMENT a:   public static void main(String args[]) {   if (args.length != 0)   System.out.println(args[args.length-1]);   }   CODE FRAGMENT b:   public static void main(String args[]) {   try { System.out.println(args[args.length]); }   catch (ArrayIndexOutOfBoundsException e) {}   }   CODE FRAGMENT c:   public static void main(String args[]) {   int ix = args.length;   String last = args[ix];   if (ix != 0) System.out.println(last);   }   CODE FRAGMENT d:   public static void main(String args[]) {   int ix = args.length-1;   if (ix > 0) System.out.println(args[ix]);   }   CODE FRAGMENT e:   public static void main(String args[]) {   try { System.out.println(args[args.length-1]);  }catch (NullPointerException e) {}   }
    A

    Code fragment a.

    B

    Code fragment b.

    C

    Code fragment c.

    D

    Code fragment d.

    E

    Code fragment e.


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

  • 第12题:

    单选题
    分析下列代码:  Class A{  Public static void main(String[] args){  method(); }  static void method(){  try{  System.out.println("Hello"); }finally{  System.out.println("good-bye"); } } }  编译运行后,输出结果是()。
    A

    Hello

    B

    good-bye

    C

    Hellogod-bye

    D

    代码不能编译


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

  • 第13题:

    阅读下面代码 public class Test { public static void main(String[]args) { System.out.println(2>0?10:8); } } 其运行的结果是

    A.2

    B.0

    C.10

    D.8


    正确答案:C

  • 第14题:

    阅读下面代码: public class Test2005 { public static void main(String args[]) { System.out.println((3>2)? 4:5); } } 其运行结果是

    A.2

    B.3

    C.4

    D.5


    正确答案:C
    解析:本程序是输出问号表达式的结果。问号表达式ex1? ex2:ex3的含义是先判断表达式ex1的值,如果该值为真,执行语句ex2,否则执行ex3。本程序中,表达式1为3>2值为真,所以结果是第二个表达式的值即4。

  • 第15题:

    下面代码的运行结果是 public class Test{ public static void main(String args[]){ for(int i=0; i<3;i++){ if(i<2) continue; System.out.println(i); } } }

    A.0

    B.1

    C.2

    D.3


    正确答案:C
    解析:本题考查简单的Java控制语句。题目非常简单,但还是应该细心。这里应注意continue语句。continue语句是跳过循环体中下面尚未执行的语句,回到循环体的开始继续下一轮的循环。当然,在下一轮循环开始前,要先进行终止条件的判断,以决定是否继续循环。对于for语句,在进行终止条件的判断前,还要先执行迭代语句。题目所给程序中,当i=0和i=1时,都会执行continue语句,而不会执行System.out.println(i)语句,只有当i=2时才执行System.out.println(i)语句,输出为2,选项C正确。

  • 第16题:

    下列代码的执行结果是( )。 public class Test{ public static void main(String[]args){ int[]x={0,1,2,3}; for{int i=0;i<3;1+=2){ try{ systcm.OUt.println(x[i+2]/x[i]+x[i+1]); }catch(ArithmeticException e){ System.OUt.println("errorl"): }catch(Exception e){ System.OUt.println("error2"): } } } }

    A.errorl

    B.error2

    C.errorl orror2

    D.2 error2


    正确答案:C
    C。【解析】当0作为除数时,会产生异常,而ArithmeticException和Exception两类异常都内部被捕捉到。

  • 第17题:

    下面程序段的输出结果是( )。 public class Test{ public static void main(String args[]){ int i=1: switch(i){ case0: System.OUt.println("0"); break; casel: System.out.println("1"); case2: System.OUt.println("2"); break; default: System.out.println("default"); } } }

    A.01

    B.12

    C.10

    D.21


    正确答案:B
    B。【解析】本题考查switch-case-break的用法。每个分支语句后面必须有break语句,否则程序向下执行,直到遇到break语句或程序结束。所以该题i=1时执行easel分支语句,而casel分支语句后没有break语句,程序继续向下执行case2分支语句,case2语句后有break语句,故程序不执行default分支语句。

  • 第18题:

    下列程序的输出结果是( )。 public class Test{ public static void main(String[]args){ int[]array=(2,4,6,8,lO); int size=6; int result =-1: try{ for(int i=0;i(size 8L&result= = -1;) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch- - -l"); } 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。【解析】由题可知先判断i<sizeresuh==-1,结果为真,则执行if语句array数组中的任何数都不等于20,并且i从0开始一直到i=5时发生越界,则输出Cateh==-2,结果为B。

  • 第19题:

    ( 17 )下列程序的输出结果是

    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 )以上都不对


    正确答案:U

    答案暂缺

  • 第20题:

    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

  • 第21题:

    public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?() 

    • A、 test
    • B、 Exception
    • C、 Compilation fails.
    • D、 NullPointerException

    正确答案:C

  • 第22题:

    Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?()   CODE FRAGMENT a:   public static void main(String args[]) {   if (args.length != 0)   System.out.println(args[args.length-1]);   }   CODE FRAGMENT b:   public static void main(String args[]) {   try { System.out.println(args[args.length]); }   catch (ArrayIndexOutOfBoundsException e) {}   }   CODE FRAGMENT c:   public static void main(String args[]) {   int ix = args.length;   String last = args[ix];   if (ix != 0) System.out.println(last);   }   CODE FRAGMENT d:   public static void main(String args[]) {   int ix = args.length-1;   if (ix > 0) System.out.println(args[ix]);   }   CODE FRAGMENT e:   public static void main(String args[]) {   try { System.out.println(args[args.length-1]);  }catch (NullPointerException e) {}   }  

    • A、Code fragment a.
    • B、Code fragment b.
    • C、Code fragment c.
    • D、Code fragment d.
    • E、Code fragment e.

    正确答案:A

  • 第23题:

    单选题
    public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()
    A

     finally

    B

     exception finished

    C

     finally exception finished

    D

     Compilation fails.


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

  • 第24题:

    单选题
    public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?()
    A

     test

    B

     Exception

    C

     Compilation fails.

    D

     NullPointerException


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