Unit 3 AP Computer Science A Practice Exam
Boolean Expressions and if Statements
Section I – Multiple Choice
Optional Time – 20 minutes
15 Questions
1) Determine the output of the 4) The ==, !=, >, <, >=, and <=
following code: operators are?
(A) Arithmetic Operators
(B) Compound Assignment
Operators
(A) true (C) Relational Operators
(B) false (D) Conditional Operators
(C) Nothing would output
(D) An error would occur 5) Which of the following are true
about conditional statements?
2) Determine the output of the
following code: I. Conditional statements interrupt
the sequential execution of
statements.
II. The code inside of an if statement
may not always run in a program,
so essential, configuring code
(A) true usually will be outside of one.
(B) false III. if statements affect the flow of
(C) Nothing would output control by executing different
(D) An error would occur statements based on the value of
a boolean expression.
3) According to DeMorgan’s laws,
which of the following statements (A) I only
are equivalent to the one below? (B) II only
(C) I and II
boolean a = !(x<3 && y>2); (D) II and III
(E) I, II, and III
I. boolean a = !(x<3) && !(y>2);
II. boolean a = !(x<3) || !(y>2);
III. boolean a = (x>=3 || y<=2);
(A) I only
(B) II only
(C) I and II
(D) II and III
(E) I, II, and III
This practice test was created by Ajay Gandecha.
This test and I are not affiliated with, or endorsed by, the College Board.
No questions are copied from the College Board and were made on my own for you to prepare.
Good luck!
6) In order for there to be output from 9) Which of the following are true
the code below, what would the about the concept of short circuit
value of “?” need to be? evaluation?
I. If the first condition of an && is
false, the second condition is not
necessarily checked.
II. If the first condition of an | | is
(A) 7 true, the second condition is not
(B) 26 necessarily checked.
(C) 53 III. If the first condition of an | | is
(D) 77 false, the second condition is not
necessarily checked.
7) Which of the following is FALSE
about the following code? (A) I only
(B) II only
(C) I and II
(D) I and III
(E) II and III
I. In its current state, the code will
produce an error. 10) Which of the following logical
II. In its current state, the code will operators is NOT paired to its
never produce any output. function?
III. If an else statement was added,
the code inside of that will (A) ! = “Not”, negates a value
always run in the if statement’s (B) && = “And”, returns true if
current state. both expressions are true
(C) | | = “Or”, returns true if one
(A) I only expression is true
(B) II only (D) None of the above
(C) I and II
(D) II and III 11) How many syntax errors are in the
code shown below?
8) What is the value of the variable
grade after the code is run below, if
the variable score is initialized to the
value of 86?
(A) 1
(B) 2
(C) 3
(A) “B” (D) 4
(B) “C” (E) 5
(C) “D”
(D) “F”
This practice test was created by Ajay Gandecha.
This test and I are not affiliated with, or endorsed by, the College Board.
No questions are copied from the College Board and were made on my own for you to prepare.
Good luck!
12) Determine the output of the 15) What program best represents the
following code: control flow diagram below?
only this line is part of
if-statement due to no
braces and only 1
line will count
(A) Hello
(B) World
(C) Hello
World
(D) Nothing will be printed. (A)
13) Which of the following is equivalent
to the following code segment?
(A) x = 8;
(B) if (x > 3) x *= 4; (B)
(C) if (x > 3) x = 8;
(D) if (x > 3) x=8; else x *= 4;
14) Determine the output of the
following code:
(C)
(A) true
true
(B) true
false
(C) false
true
(D) false
false
(D) None of the above
END OF SECTION I
This practice test was created by Ajay Gandecha.
This test and I are not affiliated with, or endorsed by, the College Board.
No questions are copied from the College Board and were made on my own for you to prepare.
Good luck!
Section II – Free Response Section
Optional Time – 15 minutes
2 Questions
1) Fill in the truth table according to the blanks already filled in below.
A B !A A && B A||B
T T
T F
F T
F F
2) Using the grading scale A: 90-100, B: 80-89, C: 70-79, D, 60-69, F: 0-59, write a
program that takes in a double variable myGrade and prints out the letter grade earned.
Use conditionals in your answer.
if myGrade >= 90
System.out.println("A")
elif myGrade >= 80
System.out.println("B")
elif myGrade >= 70
System.out.println("C")
elif myGrade >= 60
System.out.println("D")
else
System.out.println("F)
END OF SECTION II
This practice test was created by Ajay Gandecha.
This test and I are not affiliated with, or endorsed by, the College Board.
No questions are copied from the College Board and were made on my own for you to prepare.
Good luck!