Name: 
 

AP Computer Science Java - Unit 2 Practice MC Test



Multiple Choice
Identify the letter of the choice that best completes the statement or answers the question.
 

 1. 

If the operator AND is used, which of the following will make the whole condition true?
a.
first operand true, second operand false
c.
both operands true
b.
first operand false, second operand true
d.
both operands false
 

 2. 

The condition specified for an if or an if-else statement must be a(n) _________________ expression.
a.
Boolean
c.
relational
b.
arithmetic
d.
assignment
 

 3. 

For which of the following values of x and y is the expression (x>3) || (y<=5) FALSE?
a.
x=3, y=6
c.
x=7, y=2
b.
x=5 y=4
d.
x=1, y=5
 

 4. 

Of Java's three logical operators, which comes first in the order of operations?
a.
NOT
c.
OR
b.
AND
d.
XOR
 

 5. 

Which of the following statements contain a syntax error? Assume: int  X, Y, Z;
  
I.    if X>3 {System.out.println(“Hello”);}
II.   if(Z=Y) System.out.println(“How are you?”);
III.  if(X>3) System.out.println(“Just fine.”)
            else System.out.println(“And yourself?”);
a.
I and II
b.
I and III
c.
II and III
d.
I, II and III
e.
none
 

 6. 

What is the value of y after the following if the value of x is 5?
if (x<5){y=2*x+1;} else {y=2*x;}
if (y%2==0) {y=y+3;}
a.
10
c.
13
b.
11
d.
14
 

 7. 

Checking to see that an input value is appropriate is called ___________ checking.
a.
error
b.
range
c.
domain
d.
region
 

 8. 

Which value of x would cause the computer to “short-circuit”on the following OR expression?
           
       X<5 || X>7
a.
x = 4
b.
X = 5
c.
X = 6
d.
X = 7
e.
X = 8
 

 9. 

The Boolean expression !(E && F) is equivalent to.
a.
E || F
b.
!E || !F
c.
E && F
d.
!E && !F
e.
!(E || F)
 

 10. 

If X, Y and Z are Boolean variables, which of the following evaluates to FALSE? Assume that X=true, Y=false and Z=false.
a.
(X || Z) && !Y
b.
!(X && Z) || Y
c.
X || Z && ! Y || Z
d.
!(X || Z && Y && X)
e.
Y && Z || !Y && X
 



 
Check Your Work     Start Over