WorksheetsUnit 2 Quiz 1 - Java Logical & Relational Operators
Total questions: 15
Worksheet time: 8mins
Determine whether each Java expression evaluates to true or false. 12 < 5
True
False
Determine whether each Java expression evaluates to true or false. 25 >= 25
True
False
Determine whether each Java expression evaluates to true or false. "Code".equals("Code")
True
False
Determine whether each Java expression evaluates to true or false. 15 < 20 && 15 >= 10
True
False
Determine whether each Java expression evaluates to true or false. 42 > 100
True
False
Determine whether each Java expression evaluates to true or false. 8 >= 12
True
False
Determine whether each Java expression evaluates to true or false.
9 > 5 || 9 >= 20
True
False
Determine whether each Java expression evaluates to true or false. "Code".equals("code")
True
False
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)
I only
I and III
II and III
II and IV
Which Java expression is used for sorting a list of movie titles alphabetically?
equals()
==
compareTo()
&&
A login system allows access using either username or email. Which operator is correct?
||
&&
!
&
What will be printed when the following statement is run?
System.out.println("Java".compareTo("Jade"));
1
-18
18
-1
What will be printed?
Car c1 = new Car(); Car c2 = new Car(); System.out.println(c1 == c2);
A. Compile-time error
B. false
C. 0
D. true
Which Boolean operator is represented by the overlapping shaded region of a Venn diagram for A and B?
||
&&
!
&
Which statements about relational and logical operators are true? (Select all that apply.)
A. Logical operators only work with Booleans.
B. Relational operators can compare numeric values; logical operators need Booleans.
C. Both can compare Strings.
Both return Boolean results.
