AP Computer Science A Practice Quiz: Expressions and Output
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 16 questions to check your progress.
Question 1 of 16
All Questions (16)
A) Hello World
B) HelloWorld
C) Hello World
D) World Hello
Correct Answer: A
The `System.out.println` command displays the string and then moves the cursor to a new line. Therefore, "Hello" is printed on the first line, and "World" is printed on the second line.
A) AP Exam
B) APExam
C) AP Exam
D) Exam AP
Correct Answer: C
The `System.out.print` command displays the string but does not move the cursor to a new line. The first statement prints "AP " (including the space), and the second statement prints "Exam" immediately after it on the same line.
A) 16
B) 11
C) 13
D) 10
Correct Answer: B
According to the rules of operator precedence, multiplication is performed before addition. The expression is evaluated as 5 + (3 * 2), which simplifies to 5 + 6, resulting in 11.
A) 'Hello, World!'
B) (Hello, World!)
C) "Hello, World!"
D) Hello, World!
Correct Answer: C
The provided content states that "A string literal is a sequence of characters enclosed in double quotes."
A) OneTwo Three
B) One TwoThree
C) OneTwoThree
D) One Two Three
Correct Answer: A
`System.out.print("One")` prints "One" and leaves the cursor. `System.out.println("Two")` prints "Two" on the same line and then moves the cursor to the next line. `System.out.print("Three")` prints "Three" on this new line.
A) 1
B) 10
C) 25
D) 2.5
Correct Answer: C
Division and multiplication have the same precedence. Therefore, the expression is evaluated from left to right. First, 10 / 2 is calculated, which is 5. Then, 5 * 5 is calculated, which results in 25.
A) Line 1\nLine 2
B) Line 1 Line 2
C) Line 1 Line 2
D) Line 1Line 2
Correct Answer: C
The escape sequence `\n` represents a newline character. When included in a string literal, it causes the output to move to the next line at that position.
A) He said, "Java is fun!"
B) He said, \"Java is fun!\"
C) He said, Java is fun!
D) The code will produce a compilation error.
Correct Answer: A
The escape sequence `\"` is used to include a double quote character within a string literal. The backslash indicates that the following double quote is part of the string, not the end of it.
A) 3
B) 2
C) 3.4
D) 1
Correct Answer: B
The remainder operator (%) calculates the remainder of an integer division. When 17 is divided by 5, the result is 3 with a remainder of 2.
A) 11
B) 21
C) 16
D) 8
Correct Answer: B
Following operator precedence, division and multiplication are done first, from left to right. 10 / 2 is 5, and 3 * 2 is 6. The expression becomes 20 - 5 + 6. Then, addition and subtraction are done left to right. 20 - 5 is 15. Finally, 15 + 6 is 21.
A) File path: C:\\Temp\\notes.txt
B) File path: C:Tempnotes.txt
C) File path: C:\Temp\notes.txt
D) The code will produce a compilation error.
Correct Answer: C
The escape sequence `\\` is used to include a single backslash character within a string literal. Each `\\` in the code is rendered as a single `\` in the output.
A) Addition has precedence over subtraction.
B) Operators with the same precedence are evaluated from right to left.
C) Multiplication and division have precedence over addition and subtraction.
D) The remainder operator has the lowest precedence.
Correct Answer: C
The content explicitly states: "Multiplication, division, and remainder have precedence over addition and subtraction."
A) 25
B) 2 5
C) 2 5
D) 7
Correct Answer: A
`System.out.print(10 / 5)` evaluates the expression to 2 and prints it without a new line. The cursor remains after the '2'. `System.out.println(1 + 4)` evaluates the expression to 5, prints it on the same line, and then moves the cursor to the next line. The combined output is `25`.
A) `System.out.println` can only be used with string literals.
B) `System.out.print` cannot evaluate arithmetic expressions.
C) `System.out.println` moves the cursor to a new line after output, while `System.out.print` does not.
D) There is no functional difference; they are interchangeable.
Correct Answer: C
The provided content states, "System.out.println moves the cursor to a new line," which is the key distinction from `System.out.print`.
A) 4
B) 1
C) 6
D) 0
Correct Answer: A
Operators with higher precedence (%, *) are evaluated first, from left to right. First, 10 % 3 results in 1. The expression becomes 3 + 1 * 2 - 1. Next, 1 * 2 results in 2. The expression becomes 3 + 2 - 1. Then, operators with lower precedence (+, -) are evaluated left to right. 3 + 2 is 5. The expression becomes 5 - 1, which results in 4.
A) 92
B) 72
C) 7 2
D) 9 2
Correct Answer: B
The first statement evaluates 1 + 2 * 3. Multiplication has precedence, so 2 * 3 is 6, and 1 + 6 is 7. `System.out.print` displays '7' without a newline. The second statement evaluates 10 % 4, which is 2. `System.out.print` displays '2' on the same line. The final output is '72'.