InstructionsTotal Questions: 45Total Minutes: 45This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on Java Loops like WHILE Loop, FOR Loop, DO WHILE Loop and Enhanced FOR Loop. Break and Continue are also tested. This test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Java basics. Go through the above Java notes on these topics before attempting this test. All the Best Challenge SCORE0 / 45Take This Exam 1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20*21*22*23*24*25*26*27*28*29*30*31*32*33*34*35*36*37*38*39*40*41*42*43*44*45*Q Buttons 1) What is a Loop in Java programming language? A) A Loop is a block of code that is executed repeatedly as long as a condition is satisfied. B) A Loop is a block of code that is executed only once if the condition is satisfied. C) A Loop is a block of code that is executed more than 2 times if the condition is satisfied. D) None 2) Choose a valid loop name in Java below. A) for B) while C) do while D) All 3) Every loop in Java has a condition that should be ___ in order to proceed for execution. (TRUE / FALSE) A) FALSE B) TRUE C) - D) - 4) Choose the correct syntax of the WHILE loop in Java below. A) while(condition) { //statements } B) while(condition); { //statements } C) while { //statements }(condition) D) None 5) Choose the correct Syntax of FOR loop in Java below. A) for(initialization; condition; increment-or-decrement) { //statements } B) for(condition; increment-or-decrement; initialization) { //statements } C) for(increment-or-decrement; condition; initialization) { //statements } D) None 6) Choose the correct syntax of the DO WHILE loop in Java below. A) do { //statements }while(condition); B) do { //statements }while(condition) C) do while(condition) { //statements } D) None 7) Choose the correct syntax of an Enhanced FOR loop in Java below. A) for(Type variable: Collection) { //statements } B) for(Type variable; Collection) { //statements } C) for(Collection: Type variable) { //statements } D) None Ad 8) State TRUE or FALSE. A WHILE loop in Java executes the statements at least once even the condition is not satisfied. A) FALSE B) TRUE C) - D) - 9) A BREAK statement inside a Loop like WHILE, FOR, DO WHILE and Enhanced-FOR causes the program execution ___ Loop. A) Exit B) Continuation with next iteration C) Never exit D) None 10) A CONTINUE statement inside a Loop like WHILE, FOR, DO-WHILE and Enhanced-FOR causes the program execution ___ the loop. A) Skip B) Skip present iteration and continue with next iteration of the loop C) Exit D) None 11) Choose the Java-Code below with a never-ending loop. A) while(true); B) for(;true;); C) do { ; }while(true); D) All 12) A loop in Java generally contains a Loop-Counter variable. State TRUE or FALSE. A) FALSE B) TRUE C) - D) - 13) An Increment operator "++" and/or a Decrement operator "--" are used along with a Loop-Counter variable in Java. (TRUE / FALSE). A) FALSE B) TRUE C) - D) - 14) What is the output of the below Java program? int a=1; while(a<4) { System.out.print(a + " "); a++; } A) 1 2 3 4 B) 1 2 3 C) 6 D) Compiler error Ad 15) What is the output of the below Java program with a decrement operator and WHILE-loop? int a=4; while(a>0) { System.out.print(a + " "); a--; } A) 4 3 2 1 B) 3 2 1 C) Compiler error D) None 16) What is the output of the below Java program? String str="FOX"; int i=0; while(i<str.length()) { System.out.print(str.charAt(i)); i++; } A) FFF B) FOX C) Compiler error D) None 17) What is the output of the below Java program with WHILE, BREAK and CONTINUE? int cnt=0; while(true) { if(cnt > 4) break; if(cnt==0) { cnt++; continue; } System.out.print(cnt + ","); cnt++; } A) 0,1,2,3,4, B) 1,2,3,4, C) 1,2,3,4 D) Compiler error 18) What is the main difference between a WHILE and a DO-WHILE loop in Java? A) WHILE loop executes the statements inside of it at least once even if the condition is false. B) DO-WHILE loop executes the statements inside of it at least once even if the condition is false. C) WHILE loop is fast. D) DO-WHILE loop is fast. 19) What is the value of "age" in the below Java program with a DO-WHILE loop? int age=20; do { age++; }while(age<20); System.out.println(age); A) 20 B) 21 C) Compiler error D) None 20) What is the output of the below java program that implements nesting of loops? int i=1, j=1; while(i<3) { do { System.out.print(j + ","); j++; }while(j<4); i++; } A) 1,2,3,4,1,2,3,4, B) 1,2,3,4, C) 1,2,3,1,2,3, D) 1,2,3, 21) What is the output of the below Java program? int time=50; do { System.out.print(time + ","); time++; }while(time < 53) A) 50,50,50, B) 50,51,52, C) 51,52,53, D) Compiler error Ad 22) What is the output of the below Java program? char ch[] = {'A', 'B', 'C'}; int i=0; do { System.out.print(ch[i] + ","); i++; }while(i < ch.length); A) A,B,C, B) A,B,C C) A,A,A D) Compiler error 23) What is the output of the below Java program? String str[] = {"A","B","C"}; int i=0; do { if(i>= str.length) break; System.out.print(str[i] + ","); i++; }while(true); A) A,B,C, B) A,B,C C) Runtime Exception with Index Of Bounds Exception D) Compiler error 24) What is the output of the below Java code with a FOR loop? for(int i=1; i<5; i++) { System.out.print(i +","); } A) 1,2,3,4, B) 1,2,3,4 C) 1,2,3,4,5, D) 1,2,3,4,5 25) What is the output of the below Java code? boolean[] ary = {true, false, true, true}; for(int i=0; i<ary.length; i++) { System.out.print(ary[i] +","); } A) true,true,true,true, B) true,false,false,true C) true,false,true,true D) Compiler error 26) What is the output of the below Java code? int score=1; for(; true; score++) { System.out.print(score +","); if(score > 3) break; } A) 1,2,3, B) 1,2,3 C) 1,2,3,4, D) 1,2,3,4 27) What is the output of the below Java program with FOR loop? for(int j=0; j<5;j++;) System.out.print(j + ","); A) 1,2,3,4, B) 0,1,2,3,4 C) Compiler error D) None 28) State TRUE or FALSE. In a FOR loop, the Initialization-part, Condition-part and Increment/Decrement part can be empty. A) FALSE B) TRUE C) - D) - Ad 29) Any loop can be nested inside any loop in Java. (TRUE/FALSE). A) FALSE B) TRUE C) - D) - 30) A Loop in Java language may contain ___. A) Any loop B) IF-ELSE statements C) SWITCH statements D) All 31) In Java language, BREAK or CONTINUE statements can be implemented inside a Loop only with the help of ___ statements to avoid never-ending loops. A) IF ELSE B) SWITCH C) ENUM D) None 32) The Enhanced FOR loop in Java was introduced by ___. A) JDK 4 B) JDK 5 C) JDK 6 D) JDK 7 33) An enhanced FOR loop work with only Collection type data. Examples of Collection are ___. A) Array Class type or any regular array variable B) ArrayList C) HashMap, HashSet D) All 34) What is the output of Java Enhanced FOR loop below? String names[] = {"MOGLI", "SHAREKHAN", "BALU"}; for(String str: names) { System.out.print(str + ","); } A) MOGLI, B) MOGLI,SHAREKHAN, C) MOGLI,SHAREKHAN,BALU, D) Compiler error 35) An Enhanced FOR loop in Java misses ___ and __ compared to the old-style FOR loop. A) Speed and Easiness B) Initialization, Increment/Decrement C) Semicolons, Variables D) None Ad 36) What is the output of the Java program with Enhanced FOR loop below? String countries[] = {"BRAZIL", "CHILE", "SYDNEY"}; int i=0; for(String str: countries) { if(i<2) ; else break; System.out.print(str + ","); i++; } A) BRAZIL,CHILE,SYDNEY, B) BRAZIL,CHILE, C) BRAZIL, D) Compiler error 37) What is the output of the Java code snippet? int i=0; for(i=1; i<=6;i++) { if(i%3==0) continue; System.out.print(i+","); } A) 1,2, B) 1,2,4,5, C) 3,6, D) Compiler error 38) A BREAK or CONTINUE statement applies only to the ___ loop. A) Inner loop or the loop containing break or continue B) always Outer loop C) Sometimes inner loop, sometimes outer loop D) None 39) A BREAK-WITH-LABEL or CONTINUE-WITH-LABEL are used in particular in Java to select __ loop either to Break or Continue. A) Inner loop B) Outer loop C) - D) - 40) Choose rules for naming a Label in Java below. A) The name of a label or identifier may start only with Alphabet, Underscore ( _ ) or Dollar ($) symbol B) A label is kept before the loop in general C) Duplicate label names are not allowed D) All 41) State TRUE or FALSE. You can exit an inner loop without using a BREAK statement but with a CONTINUE and Label on the outer loop. A) FALSE B) TRUE C) - D) - 42) The keyword "goto" can be used in Java programs with labels. (TRUE/FALSE) A) FALSE B) TRUE C) - D) - Ad 43) Is it possible to break all loops with a single BREAK with a Label statement? (YES/NO) A) YES B) NO C) - D) - 44) What is the output of the Java code snippet below? outer: for(int i=1; i<=4;i++) { inner: for(int j=1; j<=4;j++) { if(j==1) break outer; } System.out.print("A"); } A) A B) AAAA C) No Output D) Compiler error 45) What is the output of the below Java program? outer: for(int i=1; i<=2;i++) { inner: for(int j=1; j<=2;j++) { if(j>i) break inner; System.out.print(j +","); } } A) 1,1,1 B) 1,2,2, C) 1,1,2, D) Compiler error FINISH EXAM 1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20*21*22*23*24*25*26*27*28*29*30*31*32*33*34*35*36*37*38*39*40*41*42*43*44*45*PREVJava SWITCH Case Online Test NEXTJava Multidimensional Arrays Online Test Certification Group ID 3845