Given the code fragment:
What is the result?
A. A B C Work done
B. A B C D Work done
C. A Work done
D. Compilation fails
Given the code fragment:
What is the result?
A. A B C Work done
B. A B C D Work done
C. A Work done
D. Compilation fails
C
public static void main(String[] args) {
String [] strArray = {“A”,”B”,”C”,”D”};
for(int i=0;i<strArray.length;i++){
System.out.print(strArray[i]+" ");
if(strArray[i].equals("C")){
continue;
}
System.out.println("Work done");
break; //because of break print only A and Work done
}
}
Answer C:
It will print “A” then it will jump the “Work done” because the condition is not met, and then it will break.
Answer is C
A -> print A, (if condition is not met), print Work Done, break;
Answer B