运行下列代码,当输入的num值为a时,系统会输出 ( )public static void main(String[] args){Scanner input = new Scanner(System.in);try{int num = input.nextInt();System.out.println("one");}catch(Exception e) {System.out.println("two");} finally {System.out.println("three");}System.out.println("end");}
A. one three end
B. two three end
C. one two three end
D. two end
查看答案
运行下列代码,输出结果为 ()public static void main(String[] args){try {int a = 1-1;System.out.println("a = " + a);int b = 4 / a;int c[] = {1};c[10] = 99;} catch(ArithmeticException e) {System.out.println("除数不允许为0");} catch(ArrayIndexOutOfBoundsException e) {System.out.println("数组越界");}}
A. a = 0
B. a = 0除数不允许为0
C. a = 1数组越界
D. a = 0除数允许为0
假设要输入的id值为a101,name值为Tom,程序的执行结果为 ()public static void main(String[] args) {Scanner input = new Scanner(System.in);try {int id = input.nextInt();String name = input.next();System.out.println("id = " + id + "\n" + "name" + name);} catch(InputMismatchException ex) {System.out.println("输入数据不合规范");System.exit(1);ex.printStackTrace();} finally {System.out.println("输入结束");}}
A. id=a101name=Tom
B. id=a101name=Tom输入结束
C. 输入数据不合规范
D. 输入数据不合规范输入结束java.util.InputMismatchException…
下列代码的运行结果为 ( )public static int test(int b) {try {b += 10;return b;} catch(Exception e) {return 1;} finally {b += 10;return b;}}public static void main(String[] args) {int num = 10;System.out.println(test(num));}
A. 1
B. 10
C. 20
D. 30
在下列代码划线处不可以填入选项中的是哪一个异常类型( )public static int test(int a, int b) throwsArithmeticException{if(b == 0){throw ______;}else {return (a/b);}}
A. new Throwable()
B. new Exception()
C. new InputMismatchException()
D. new ArithmeticException("算术异常")