Image Courtesy of Wikipedia.
β
STOP!β Before you look at the answers make sure you gave this practice quiz a try so you can assess your understanding of the concepts covered in unit #. Click here for the practice questions:
AP Comp Sci A Unit 4 Multiple Choice Questions.
Facts about the test: The AP Computer Science A exam has 40 multiple choice questions and you will be given 90 minutes to complete the section. That means it should take you around 34 minutes to complete 15 questions.
*The following questions were not written by CollegeBoard and although they cover information outlined in the AP Computer Science A Course and Exam Description the formatting on the exam may be different.
1. In programming, what is an iteration?
A. A decision point in a program
B. Testing a program to make sure it works
C. The repetition of steps in a program
D. The order that instructions are carried out in a program
Answer: The answer to this question is the simple definition of iteration.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
2. In programming, why is iteration important or useful?
A. it allows code to be simplified by removing repeated steps
B. it guarantees that the code runs correctly
C. it determined the order that the steps of the code are carried out
D. it allows multiple paths through a program
Answer: Iteration is an abstraction or a way to simplify code.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
3.Β Which two statements are used to implement iteration?
A. WHILE and IF
B. FOR and WHILE
C. IF and ELSE
D. ELSE and WHILE
Answer: FOR and WHILE signify the use of iteration.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
4. Which type of loop iterates until instructed otherwise?
A. FOR loop
B. Repeat-once loop
C. WHILE loop
D. A count-controlled loop
Answer: The WHILE loop is checked at the end, which will instruct the "otherwise" part, causing an end to the loop.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
5. The condition for a WHILE loop to continue could be which of the following?
A. While something is true
B. While something is equal to something else
C. While something is greater than something else
D. All of the above
Answer: All are examples of checks for the WHILE loop.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
6. What is the output for the following code?
A. 0 3 6 9 12
B. 12 9 6 3 0
C. 0 3 6 9
D. 9 6 3 0
Answer: Starts by printing 0 (eliminate 2 choices).. then increase by 3 in iteration, continue display until reaching 12 (but not including 12)
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
7.Β What is the output for the following code?
A. Hello world! Β Hello world! Β Hello world! (repeated without end)
B. Hello World!
C. error
D. Hello, World
Answer: Set to true with no change to false to trigger leaving the iteration.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
8. This causes a loop to terminate early
A. switch
B. continue
C. break
D. end
Answer: A break causes a loop to end early.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
9. This type of loop has no way of ending and repeats until the program is interrupted.
A. infinite
B. indeterminate
C. interruptible
D. timeless
Answer: This is the definition of indeterminate loop.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
10. What kind of variable controls the number of iterations performed by a loop?
A. repetition variable
B. accumulator
C. double
D. loop control variable
Answer: This is the definition of loop control variable.
π Study AP Comp Sci A, Unit 4.1: Unit 4 Overview and While Loops
11. What is the output of the following code fragment (selow)?
A. 2
B. 50
C. 75
D. 25
Answer: Loop won't run because x doesn't pass the condition (it is already > 0).
π Study AP Comp Sci A, Unit 4.2: For Loops
12. The "less than or equal to" comparison in Java is which of the following?
A. <<
B. <=
C. =<
D. <
Answer: This question tests your knowledge of Java notation.
π Study AP Comp Sci A, Unit 4.2: For Loops
13. If x is an integer and x = 1, what will be the value of x after the following loop terminates?Β
A. 2
B. 64
C. 100
D. 128
Answer: Will double until x=64*2=128.
π Study AP Comp Sci A, Unit 4.4: Nested Iteration
14. What would be printed out after the following code?Β
A. O
B. H
C. N
D. Y
Answer: Will display the character at the 5th, remember that location 1 is actually 0 location.
π Study AP Comp Sci A, Unit 4.3: Developing Algorithms Using Strings
15. What does equal ( ) return?
A. boolean
B. string
C. char
D. double
Answer: Will return type boolean.
π Study AP Comp Sci A, Unit 4.4: Nested Iteration
What can we help you do now?
π€Connect with other students studying AP Comp Sci A with Hours