OCJP Practice Papers Using Loop Constructs
OCJP Practice Papers Using Loop Constructs include following topics
- Create and use while loops
- Create and use for loops including the enhanced for loop
- Create and use do/while loops
- Compare loop constructs
- Use break and continue
See the complete syllabus for OCJP here
1. Which type of loop is best known for its boolean condition that controls entry to theloop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
2. Which type of loop is best known for using an index or counter?
A. do-while loop
B. for (traditional)
C. for-each
D. while
3. Which type of loop is guaranteed to have the body execute at least once?
A. do-while loop
B. for (traditional)
C. for-each
D. while
4. Which of the following can loop through an array without referring to the elements byindex?
A. do-while loop
B. for (traditional)
C. for-each
D. while
5. What keyword is used to end the current loop iteration and proceed execution with thenext iteration of that loop?
A. break
B. continue
C. end
D. skip
6. What keyword is used to proceed with execution immediately after a loop?
A. break
B. continue
C. end
D. skip
7. Which type of loop has three segments within parentheses?
A. do-while loop
B. for (traditional)
C. for-each
D. while
8. Which of the following statements is/are true?
I. A traditional for loop can iterate through an array starting from index 0.
II. A traditional for loop can iterate through an array starting from the end.
A. Only I
B. Only II
C. Both statements
D. Neither statement
9. Which of the following statements is/are true?
I. A for-each loop can iterate through an array starting from index 0.
II. A for-each loop can iterate through an array starting from the end.
A. Only I
B. Only II
C. Both statements
D. Neither statement
10. Which type of loop has a boolean condition that is first checked after a single iterationthrough the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
11. What does the following code output?
A. 0
B. The code does not compile.
C. The loops complete with no output.
D. This is an infinite loop.
12. What does the following code output?
A. can,cup,
B. cup,can,
C. The code does not compile.
D. None of the above
13. What does the following code output?
A. glass,end
B. glass,plastic,end
C. The code does not compile.
D. None of the above
14. What does the following code output?
A. aa
B. aaa
C. The loops complete with no output.
D. This is an infinite loop.
15. What is the result of the following when run with java peregrine.TimeLoopSeptember 3 1940?
A. args
B. argsargs
C. The code does not compile.
D. None of the above
16. What is the output of the following code?
A. 1
B. 2
C. 4
D. The code does not compile.
17. What is the result of the following code?
A. 2
B. 3
C. The code does not compile.
D. This is an infinite loop.
18. Which of the following segments of a for loop can be left blank?
A. segmentA
B. segmentB
C. segmentC
D. All of the above
19. How many of the loop types (while, do while, traditional for, and enhanced for) allowyou to write code that creates an infinite loop?
A. One
B. Two
C. Three
D. Four
20. What is the output of the following?
A. can,cup,
B. cup,can,
C. The code does not compile.
D. None of the above
21. What happens when running the following code?
A. It completes successfully without output.
B. It outputs helium once.
C. It keeps outputting helium.
D. The code does not compile.
22. Which of the following is equivalent to this code snippet given an array of Stringobjects?
A. for (String f = fun) System.out.println(f);
B. for (String f : fun) System.out.println(f);
C. for (String = fun) System.out.println(it);
D. None of the above
23. How many of these statements can be inserted after the println to have the code flowfollow the arrow in this diagram?
A. None
B. One
C. Two
D. Three
24. Using the diagram in the previous question, how many of these statements can beinserted after the println to have the code flow follow the arrow in the diagram?
A. None
B. One
C. Two
D. Three
25. What does the following code output?
A. 0
B. The code does not compile.
C. The loops completes with no output.
D. This is an infinite loop.
26. Which of the following types is taxis not allowed to be in order for this code to compile?
A. ArrayListInteger
B. int[]
C. StringBuilder
D. All of these are allowed.
27. What is the output of the following?
A. done
B. inflate-done
C. The code does not compile.
D. This is an infinite loop.
28. What does the following code output?
A. ab
B. abab
C. The loop completes with no output.
D. This is an infinite loop.
29. What describes the order in which the three expressions appear in a for loop?
A. boolean conditional, initialization expression, update statement
B. initialization expression, boolean conditional, update statement
C. initialization expression, update statement, boolean conditional
D. None of the above
30. What is the result of the following?
A. 3
B. 4
C. The code does not compile.
D. None of the above
31. What is the result of the following?
A. 1
B. 2
C. 3
D. 4
32. Which of the following is equivalent to this code snippet given an array of String objects?
A. for (String f = fun) System.out.println(f);
B. for (String f : fun) System.out.println(f);
C. for (String f fun) System.out.println(it);
D. None of the above
33. What does the following code output?
A. glass,end
B. glass,plastic,end
C. The code does not compile.
D. None of the above
34. What is the result of the following?
A. Downtown Day-
B. Downtown Day-Uptown Night-
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
35. What is the result of the following when run with java peregrine.TimeLoop September 3 1940?
A. September
B. 1940
C. The code does not compile.
D. None of the above
36. What is the output of the following?
A. null
B. shoelace
C. shoelaceshoelace
D. None of the above
37. The following code outputs a single letter x. What happens if you remove lines 25 and 28?
A. It prints an empty string.
B. It still outputs a single letter x.
C. It no longer compiles.
D. It becomes an infinite loop.
38. What is the output of the following code?
A. 1
B. 2
C. 4
D. The code does not compile.
39. What is the output of the following?
A. Leaves growing
B. This is an infinite loop.
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
40. What is the result of the following code?
A. 2
B. 3
C. The code does not compile.
D. This is an infinite loop.
41. Fill in the blank so this code compiles and does not cause an infinite loop.
A. break;
B. break f;
C. break t;
D. None of the above
42. What is the result of the following?
A. Downtown DayB.
Downtown Day-Uptown Night-
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
43. How many lines does the following code output?
A. One
B. Four
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
44. Which of the following best describes the flow of execution in this for loop if beta
always returns false?
A. alpha
B. alpha, beta
C. alpha, beta, gamma
D. None of the above
45. Which of the following best describes the flow of execution in this for loop if the loop
body is run exactly once?
A. alpha, delta, gamma, beta
B. alpha, beta, delta, gamma, beta
C. alpha, delta, gamma, alpha, beta
D. alpha, beta, delta, gamma, alpha, beta
46. Which of the following iterates a different number of times than the others?
A. for (int k=0; k 5; k++) {}
B. for (int k=1; k = 5; k++) {}
C. int k=0; do { } while(k++ 5)
D. int k=0; while (k++ 5) {}
47. What is the output of the following?
}
A. null
B. shoelace
C. shoelaceshoelace
D. None of the above
48. What is the output of the following?
A. 5
B. 8
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
49. What is the output of the following?
A. done
B. inflate-done
C. The code does not compile.
D. This is an infinite loop.
50. Which of the following can fill in the blank to have the code compile successfully?
A. int i=0; j=0;
B. int i=0, j=0;
C. int i=0; int j=0;
D. int i=0, int j=0;
OCJP Practice Test, Certification Path, Tips/Tricks
- Oracle (OCJP) Java Certification Exam
- Java Certification Tips And Tricks
- OCJP Practice Papers - Java Basics
- OCJP Practice Papers - Operators And Decision Constructs
- OCJP Practice Papers-A Advanced Java Class Design
- OCJP Practice Papers Creating And Using Arrays
- OCJP Practice Papers Using Loop Constructs
- OCJP Practice Papers - Generics And Collections
- OCJP Practice Papers - Lambda Built-In Functional Interfaces
- OCJP Practice Papers Java Class Design
- OCJP Practice Papers - Java Stream API
- OCJP Practice Papers - Exceptions And Assertions
- OCJP Practice Papers - Date/Time API
- OCJP Practice Papers - Java I/O Fundamentals
- OCJP Practice Papers - Working With Methods And Encapsulation
- OCJP Practice Papers - Working With Inheritance
- OCJP Practice Papers - Handling Exceptions
- OCJP Practice Papers - Selected Classes From Java API
- OCJP Practice Papers - Java File I/O Nio.2
- OCJP Practice Papers - Java Concurrency