Which two code fragments, independently, print each element in this array?

Given the following array: Which two code fragments, independently, print each element in
this array?

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



Leave a Reply 7

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


TC

TC

Option B and Option E

Kaykay

Kaykay

Definitely B – Option B and E – Option E.

Anurag

Anurag

its Option A and Option E

Tomas

Tomas

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 + " ");
}
*/