Given the following array: Which two code fragments, independently, print each element in
this array?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
F.
Option F
Given the following array: Which two code fragments, independently, print each element in
this array?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
F.
Option F
b and e
Option B and Option E
Definitely B – Option B and E – Option E.
its Option A and Option E
Sorry B E
Answer: B and E
// A – ERROR – Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 8
/*
for(int i : intArr){
System.out.println(intArr[i] + ” “);
}
*/
// B – OK
for(int i : intArr){
System.out.print(i + ” “);
}
// C – ERROR
/*
for(int i = 0 : intArr){
System.out.println(intArr[i] + ” “);
i++;
}
*/
// D – ERROR – worked but in wrong way
/*
for(int i = 0 ; i< intArr.length ; i++){
System.out.println(i + " ");
}
*/
// E – OK
for(int i = 0 ; i< intArr.length ; i++){
System.out.println(intArr[i] + " ");
}
// F – ERROR
/*
for(int i ; i< intArr.length ; i++){
System.out.println(i + " ");
}
*/
b,e