If/Else

If/Else

9th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

Java For Loops

Java For Loops

9th - 12th Grade

9 Qs

P5.js Variables and Conditional Statements

P5.js Variables and Conditional Statements

9th - 12th Grade

15 Qs

Sains Komputer (Java) 1: Sintaks Asas & Pembolehubah

Sains Komputer (Java) 1: Sintaks Asas & Pembolehubah

10th Grade - University

10 Qs

Java switch/for/while

Java switch/for/while

9th - 12th Grade

15 Qs

Loops

Loops

9th - 12th Grade

10 Qs

conditional constructs in Java

conditional constructs in Java

10th Grade

10 Qs

String Method

String Method

10th Grade

10 Qs

Quiz 15 - Array Basics

Quiz 15 - Array Basics

11th Grade

10 Qs

If/Else

If/Else

Assessment

Quiz

Computers

9th - 12th Grade

Hard

Used 156+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Analyze the following code:
boolean even = false;
if (even = true) {
 System.out.println("It is even!");
}
The program has a compile error.
The program has a runtime error.
The program runs, but displays nothing.
The program runs and displays It is even!.

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

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");
}
no output
No output
Income is greater than 3000 
Income is greater than 3000 followed by Income is greater than 4000
Income is greater than 4000 followed by Income is greater than 3000

3.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and 
"Can get a driver's license" if age is greater than or equal to 16. 
Which of the following code is the best?
if (age < 16) 
 System.out.println("Cannot get a driver's license");
if (age >= 16) 
 System.out.println("Can get a driver's license");
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else 
 System.out.println("Can get a driver's license");
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else if (age >= 16) 
 System.out.println("Can get a driver's license");
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else if (age > 16) 
 System.out.println("Can get a driver's license");
else if (age == 16) 
 System.out.println("Can get a driver's license");

4.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

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");
too hot
too cold
just right
too hot too cold just right

5.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Assume x = 4 and y = 5, Which of the following is true?
x < 5 && y < 5
 x < 5 || y < 5
 x > 5 && y > 5
x > 5 || y > 5

6.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

 What is the output of the following code?
char ch = 'F';
if (ch >= 'A' && ch <= 'Z')
 System.out.println(ch);
F
f
nothing
F f

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Analyze the following program fragment:
int x;
double d = 1.5;
switch (d) {
 case 1.0: x = 1;
 case 1.5: x = 2;
 case 2.0: x = 3;
}
The program has a compile error because the required break statement is missing in the switch statement.
The program has a compile error because the required default case is missing in the switch statement.
The switch control variable cannot be double.
No errors.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?