Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the printout of the following code? public class Test { public static vo

ID: 3574594 • Letter: W

Question

What is the printout of the following code?

public class Test {
public static void main(String[] args) {
int[][][] data = {{1, 2}, {3, 4},
{5, 6}, {7, 8}};

System.out.print(data[1][0][0]);
}
}

a) 1

b) 2

c) 4

d)5

e) 6

What is not a possible output from System.out.println((int)Math.random() * 4)?

a)0

b)1

c)2

d)3

e)4

What exception type does the following program throw?

public class Test {
public static void main(String[] args) {
int[] list = new int[5];
System.out.println(list[5]);
}
}

a) ArithmeticException

b) ArrayIndexOutOfBoundsException

c) StringIndexOutOfBoundsException

d)ClassCastException

e)No exception

Explanation / Answer

1.

d)5

data[1][0][0] =5 because first dimension is 1 not 0

2.

e)4

This is because Math.random() returns value from 0.0 to 1 exclusive. It never return 1 but a value smaller than 1. So 1 will never come and 1*4 will never be computed . 4 cannot be the output.

3.

b) ArrayIndexOutOfBoundsException

list[5] can have index from 0 to 4. so list[5] will throw ArrayIndexOutOfBoundsException.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote