
Unit 3 Quiz Review- Boolean expressions and Operators
Authored by Michael Courtright
Computers
11th - 12th Grade
Used 2+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
9 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which of the following examples as Java expressions would return true?
20 < 40
20>=20
"Friend".equals("Friend")
20 <35 && 15 <= 15
All of the above
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which of the following is a valid statement for comparison of the weight of three items declared as w1, w2, and w3 of double data type?
I. (w1.compareTo(w2)==0) && (w2.compareTo(w3)==0)
II. (w1 >= w2) && (w1 >= w3)
III. (w1.equals(w2)) && (w1.equals(w3)
IV. (w1 >= w2) || (w1>=w3)
I only
III only
I and III
II and IV
II and III
Answer explanation
Relational operators are used to compare values. equals() and compareTo() are methods to compare objects.
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
You want to compare the names of employees at Switch Video Games and arrange them in ascending order to make search and filtering easier and faster.
Which of the following Java expression components would you use?
>
compareTo()
<
==
equals()
Answer explanation
The compareTo() method is the method that should be used to compare two String values.
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
A programmer needs to write a code for a login screen to access the learning resources of www.javaforstudents.com. There are two options to login to the portal:
enter registered user name
or
enter registered mobile number
Which operator should the programmer use to complete this task?
&
!
|
||
&&
Answer explanation
|| (OR) operator should be used by the programmer to fulfill one of the conditions to log in to the screen.
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the code segment.
System.out.println("Joe".compareTo("Harry"));
What will be the output of this code?
-2
compile time error
-3
2
3
Answer explanation
This will compare both the Strings, and the result will be the difference between Joe and Harry, or 2.
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the code below written to compare two objects.
My m1 = new My();
My m2 = new My();
System.out.println(m1==m2);
What will be the output of the above code?
false
true
0
1
-1
Answer explanation
The == operator checks for reference equality, and it will give false.
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Which Boolean operator is represented in the shaded portion of the Venn diagram below?
|
||
&
$
&&
Answer explanation
The shaded portion in the given the Venn diagram is known as intersection and it is represented as && (AND) operator.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?