What is the result?

Given: What is the result?

Given: What is the result?

A.
91 98 99 100 null null null

B.
91 98 99 100 101 102 103

C.
Compilation rails.

D.
A NullPointerException is thrown at runtime.

E.
An ArraylndexOutOfBoundsException is thrown at runtime.

Explanation:



Leave a Reply 7

Your email address will not be published. Required fields are marked *


IO

IO

A.
91 98 99 100 null null null

but there are a problem with the test, the correst answers is
A.
97 98 99 100 null null null

Kanke

Kanke

Definitely A.

TwinForce

TwinForce

Can someone explain me the second part of this?
I don’t understand what for(String[]ca: chs)… and the other one check for?
Why run these loop three times?

Please help 🙂

Tomas

Tomas

Answer: A
Tested

alaa

alaa

public static void main(String args[]){

String[][] chs = new String[2][];
chs[0] = new String[2];
chs[1] = new String[5];
int i = 97;
for (int a = 0; a < chs.length; a++){
for (int b = 0; b < chs.length; b++){
chs[a][b] = "" + i;
i++;
}
}

for (String[] ca : chs) {
for (String c : ca){
System. out. print (c + " ");
}
System.out.println();
}

}

alaa

alaa

97 98
99 100 null null null