No student devices needed. Know more
61 questions
Which of the following is NOT a relational operator?
<
?
==
>=
What does this Java expression evaluate to?
80 >= 80
"true"
true
false
This expression will error
true
false
Cannot be determined
What is the difference between == and =?
== is used for assignment, while = is used to check for equality.
= is used for assignment, while == is used to check for equality.
== assigns values to objects while = assigns values to primitives.
There is no difference. These symbols can be used interchangeably.
Which of the following symbols is the “not equal” symbol?
==
not =
!=
<>
Why do we use if statements in Java?
To break out of some block of code
To do something only if a condition is true
To do something while a condition is true
To repeat something for a fixed number of times
Which if statement is written properly?
if (boolean expression):
// code to execute
// code to execute
if boolean expression
{
// code to execute
// code to execute
}
if(boolean expression)
{
// code to execute
// code to execute
}
if boolean expression
[
// code to execute
// code to execute
]
What is the output of this program?
It is acidic!
It is basic!
It is neutral!
It is acidic!
It is basic!
It is neutral!
How old is the tree?
Still young!
How old is the tree?
Still young!
Pretty old!
How old is the tree?
Very old!
How old is the tree?
Still young!
Pretty old!
Very old!
How old is the tree?
Still young!
How old is the tree?
Pretty old!
Very old!
How old is the tree?
Very old!
How old is the tree?
Still young!
Pretty old!
Very old!
Which statement will be executed if x = 3 and y = 3?
Statement A
Statement B
Statement A and Statement B
Impossible to tell
Statement A
Statement B
Statement A and Statement B
Impossible to tell
lastName is longer than firstName
Karel is longer than The Dog
The Dog is longer than Karel
Karel is longer than The Dog
The Dog is longer than Karel
Which of the following statements is true?
There can only be one else-if statement in an if-else if statement.
An if- else if statement must always have an else clause.
An if- else if statement cannot have an else clause.
An if- else if statement must always start with an if statement.
Tamale it is!
Quesadilla it is!
That is not a combo of ours
Tamale it is!
Quesadilla it is!
Too expensive!
Typical
Typical
Must be a scam
Typical
Great deal
C, A, D, B
D, A, C, B
C, D, A, B
A, B, C, D
Which of the below is a logical operator?
!
##
**
%
What does this Java expression evaluate to?
true && !false
true
false
Yes
No
Yes
No
What value of x would make this boolean expression evaluate to false?
(x < 10) && (x != 5)
Any value less than 10
Any value less than 10 except for 5
The only time it is false is when x = 5.
Any value greater than or equal to 10
Which of the following logical statements is equivalent to
!(A && B)
!A && B
!A && !B
!A || !B
!A || B
Which of the following logical statements is equivalent to
!(A || B)
!A && !B
!A || !B
!A || B
A && B
What boolean value is held in the following boolean variable if hasBike is true and hasHelmet is false?
boolean cannotBike = !(hasBike && hasHelmet);
True
False
What boolean value is held in the following boolean variable if hasHeadlight is true and hasBikelight is false?
boolean cannotNightBike = !(hasHeadlight || hasBikelight);
True
False
true
false
true
false
What is the proper way to compare String values in Java?
The == operator
The .equals() String method
The = operator
The | operator
str1 == str2 && str1 == str3
str1 != str2 && str1.equals(str3)
str1 == str2 && str1.equals(str3)
None of the above will evaluate to true after this code snippet executes.
Reference equality uses the equality operator (==) and compares the references (addresses in memory) of two objects.
true
false
Logical equality compares the data of the objects.
False
True
Why do we use while loops in Java?
To break out of some block of code
To do something if a condition is true
To repeat some code while a condition is true
To repeat something for a fixed number of times
Print Hello one time
Print Hello in an infinite loop
Print Hello until program receives user input
Nothing
Which statement can we use inside of a loop to end it?
System.out.println;
break;
SENTINEL;
else;
The loop doesn’t ever change the value of x in the loop, so it never ends.
The conditional with the while will never be true, so actually the code will never execute.
There’s no break statement to end the code.
The code cannot contain just a print statement.
You can add x-- after the print statement.
You can add x = -1 after the print statement.
You can add x++ after the print statement.
Both A and B above.
4 3 2 1
-4 -3 -2 -1 0
-3 -2 -1 0
3 2 1 0
10 times
9 times
1 time
0 times
A
B
C
D
(n + 1) / 2
n / 2
(n - 1) / 2
n
n-1
Why do we use for loops in Java?
To break out of some block of code
To do something if a condition is true
To do something while a condition is true
To repeat something for a fixed number of times
2, 3, 4, 5, 6, 7, 8, 9,
2, 3, 4, 5, 6, 7, 8,
0, 1, 2, 3, 4, 5, 6, 7, 8,
This code will produce an infinite loop.
Which of the following will execute without throwing an exception error?
None of the above
A and B above.
Frog
orF
ogroF
ogroFr
StringIndexOutOfBoundsException
0
1
2
-1
5
A. It may return a string that is equal to str2.
B. It may return a string that has no characters in common with str2.
C. It may return a string that is equal to str1.
Both A and C are true
None of these choices will be true.
What is the general formula for traversing a String character by character?
A rectangle of 6 rows with 4 stars per row.
A rectangle of 6 rows with 3 stars per row.
A rectangle of 5 rows with 4 stars per row.
A rectangle of 4 rows with 5 stars per row.
5 stars
10 stars
15 stars
50 stars
500 stars
0 6 12 18 24
0 3 6 9 12 15 18 21 24
0 2 4 6 8 10 12 14 16 18 20 22 24
This produces an infinite loop
How often is the inner loop of a nested loop run?
Infinitely
Twice as often as the outer loop
Each time the outer loop runs
One less time than the outer loop runs
count < 5 is always true at point 1
count < 5 always false at point 1
count < 5 is sometimes true/sometimes false at point 1
count < 5 is always true at point 2
count < 5 always false at point 2
count < 5 is sometimes true/sometimes false at point 2
count < 5 is always true at point 3
count < 5 always false at point 3
count < 5 is sometimes true/sometimes false at point 2
x times
x + 1 times
x - 1 times
Infinite number of times
The condition is never true so this loop never executes.
x times
x + 1 times
x - 1 times
Infinite number of times
The condition is never true so this loop never executes.
x times
x - 1 times
x - 5 times
Infinite number of times
The condition is never true so this loop never executes.
Why is having efficient algorithms important?
It reduces the cost of running a program.
It can improve the speed that programs operate.
It increases the speed of innovations.
Both 1 and 2.
Both 2 and 3.
Explore all questions with a free account