Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Unit 2 Quiz 1 - Java Logical & Relational Operators

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Determine whether each Java expression evaluates to true or false. 12 < 5

a)

True

b)

False

2.

Determine whether each Java expression evaluates to true or false. 25 >= 25

a)

True

b)

False

3.

Determine whether each Java expression evaluates to true or false. "Code".equals("Code")

a)

True

b)

False

4.

Determine whether each Java expression evaluates to true or false. 15 < 20 && 15 >= 10

a)

True

b)

False

5.

Determine whether each Java expression evaluates to true or false. 42 > 100

a)

True

b)

False

6.

Determine whether each Java expression evaluates to true or false. 8 >= 12

a)

True

b)

False

7.

Determine whether each Java expression evaluates to true or false.

9 > 5 || 9 >= 20

a)

True

b)

False

8.

Determine whether each Java expression evaluates to true or false. "Code".equals("code")

a)

True

b)

False

9.

Which of the following is a valid statement for comparing the heights of three buildings (double values h1, h2, h3)?

I. (h1.compareTo(h2)==0) && (h2.compareTo(h3)==0)

II. (h1 >= h2) && (h1 >= h3)

III. (h1.equals(h2)) && (h1.equals(h3))

IV. (h1 >= h2) || (h1 >= h3)

a)

I only

b)

I and III

c)

II and III

d)

II and IV

10.

Which Java expression is used for sorting a list of movie titles alphabetically?

a)

equals()

b)

==

c)

compareTo()

d)

&&

11.

A login system allows access using either username or email. Which operator is correct?

a)

||

b)

&&

c)

!

d)

&

12.

What will be printed when the following statement is run?

System.out.println("Java".compareTo("Jade"));

a)

1

b)

-18

c)

18

d)

-1

13.

What will be printed?

Car c1 = new Car(); Car c2 = new Car(); System.out.println(c1 == c2);

a)

A. Compile-time error

b)

B. false

c)

C. 0

d)

D. true

14.

Which Boolean operator is represented by the overlapping shaded region of a Venn diagram for A and B?

a)

||

b)

&&

c)

!

d)

&

15.

Which statements about relational and logical operators are true? (Select all that apply.)

a)

A. Logical operators only work with Booleans.

b)

B. Relational operators can compare numeric values; logical operators need Booleans.

c)

C. Both can compare Strings.

d)

Both return Boolean results.