Java Programming Quiz 3 – Flashcards
Unlock all answers in this set
Unlock answersquestion
What is the value of the following expression?
true || true && false
answer
true
question
The following code displays ________.
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");
answer
just right
question
The "less than or equal to" comparison operator in Java is ________.
answer
<=
question
What is the printout of the following switch statement?
char ch = 'b';
switch (ch) {
case 'a':
System.out.print(ch);
case 'b':
System.out.print(ch);
case 'c':
System.out.print(ch);
case 'd':
System.out.print(ch);
}
answer
bbb
question
What is the printout of the following switch statement?
char ch = 'a';
switch (ch) {
case 'a':
case 'A':
System.out.print(ch); break;
case 'b':
case 'B':
System.out.print(ch); break;
case 'c':
case 'C':
System.out.print(ch); break;
case 'd':
case 'D':
System.out.print(ch);
}
answer
a
question
What is y after the following statement is executed?
x = 0;
y = (x > 0) ? 10 : -10;
answer
-10
question
Which of the following statements are true? (Choose three.)
answer
(x > 0 && x < 10) is same as ((x > 0) && (x < 10))
(x > 0 || x < 10) is same as ((x > 0) || (x < 10))
(x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0))
question
What is 1 + 1 + 1 + 1 + 1 == 5?
answer
true
question
To check whether a char variable ch is an uppercase letter, you write ________.
answer
(ch >= 'A' && ch <= 'Z')
question
Suppose income is 4001, what is the output of the following code:
if (income > 3000) {
System.out.println("Income is greater than 3000");
}
else if (income > 4000) {
System.out.println("Income is greater than 4000");
}
answer
Income is greater than 3000
question
Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
answer
((x < 100) && (x > 1)) || (x < 0)
question
Which of the Boolean expressions below is incorrect? (Choose three.)
answer
(-10 < x < 0)
(x != 0) || (x = 0)
(true) && (3 => 4)
question
What is the output of the following code?
char ch = 'F';
if (ch >= 'A' && ch <= 'Z')
System.out.println(ch);
answer
F
question
Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println("It is even!");
}
answer
It is even!
question
Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?
if (x > 0)
if (y > 0)
System.out.println("x > 0 and y > 0");
else if (z > 0)
System.out.println("x < 0 and z > 0");
answer
x < 0 and z > 0;
question
Analyze the following code.
boolean even = false;
if (even) {
System.out.println("It is even!");
}
answer
The code displays nothing.
question
What is 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0?
answer
There is no guarantee that 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0 is true.
question
The equal comparison operator in Java is ________.
answer
==
question
Analyze the following code:
if (x < 100) && (x > 10)
System.out.println("x is between 10 and 100");
answer
The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.
question
Which of the following code displays the area of a circle if the radius is positive?
answer
if (radius > 0) System.out.println(radius * radius * 3.14159);