Return to site

JAVA CERTIFICATION QUESTION: Break and continue in Java’s for loops

· java

Sometimes you have to simulate JVM behavior using pencil and paper.

Given the following code fragment:

String[] nums = {"One", "Two", "Three", "Four", "Five", "Six", "Sev"};
for(int i = 0; i < nums.length; i++) {
   if (nums[i++].length() % 3 == 0) {
      continue;
   }
   System.out.println(nums[i]);
   break;
}

What is the output? Choose one.

A. Three

B. Four

C. Five

D. Three

Four

Five

E. No output

 

 

 

 

·ꓭ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ