运行下面程序时,会产生什么异常?( )public class sdw{ public static void main(String[] args) {int x = 0;int y = 5/x;int[] z = {1,2,3,4};int p = z[3];}}
A: ArithmeticException
B: NumberFormatException
C: ArrayIndexOutOfBoundsException
D: IOException
A: ArithmeticException
B: NumberFormatException
C: ArrayIndexOutOfBoundsException
D: IOException
举一反三
- 运行下面程序时,会产生什么异常? public class X7 { public static void main(String[] args) { int x = 0; int y = 5/x; int[] z = {1,2,3,4}; int p = z[4]; } }
- 运行下面的程序时,会产生( )。 public class Test{ public static void main(String args[ ] ) { int x =0; int y = 2/x; int z[ ] = {1,2,4,6}; int p=z[4]; } } A: ArrayIndexOutOfBoundsExcePtion异常 B: NumberFormatException异常 C: ArithmeticException异常 D: ArithmeticException异常和ArrayIndexOutOfBoundsExcePtion异常
- 请阅读程序,然后写出程序运行结果。 public class Demo7 { public static void main(String[] args) { int [] arr= new int[5]; int sum=0; Arrays.fill(arr, 3); for(int x:arr) { sum=sum+x; } System.out.println(sum); } }
- (7-13)请阅读程序,写出程序运行结果。 //运行结果题 public class Demo4 { public static int print(Object obj) { int []arr; int sum=1; if(obj instanceof int[]) { arr=(int[])obj; for(int x:arr) { sum=arr.length+sum; } } return sum; } public static void main(String[] args) { int []arr= {1,2,3,4,5}; String [] list= {"孙悟空","猪八戒","唐僧"}; System.out.println(print(arr)+print(list)); } }
- 仔细阅读程序,确定a,z的值? public class Example16{ public static void main(String[] args) { int x = 0; int y = 0; int z = 0; boolean a; a = x == 0 || z++ >1; System.out.println("a = " + a); System.out.println("z = " + z); } }