Test Series - java

Test Number 36/64

Q: 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
Solution: A Java loop is similar to a C style loop.
Q: Choose a valid loop name in Java below.
A. for
B. while
C. do while
D. All
Solution: no solution
Q: Every loop in Java has a condition that should be ___ in order to proceed for execution. (TRUE / FALSE)
A. FALSE
B. TRUE
C. ....
D. None
Solution: no solution
Q: 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
Solution: Answer B has a WHILE loop immediately terminated by a Semicolon. So it is a wrong representation.
Q: 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
Solution: Notice that there is no semicolon at the end of the INCREMENT/DECREMENT part.
Q: 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
Solution: There must be a Semicolon at the end of the while(condition) part when writing a DO-WHILE loop.
Q: 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
Solution: There should be a COLON before the collection variable name in the Enhanced FOR loop.
Q: 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. None
Solution: Only the DO WHILE loop executes the statements at least once.
Q: 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
Solution: no solution
Q: 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
Solution: no solution

You Have Score    /10