If/Else

If/Else

9th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

Reconstruction Quiz

Reconstruction Quiz

9th - 11th Grade

10 Qs

processing methods

processing methods

10th Grade

11 Qs

Python Revision

Python Revision

11th - 12th Grade

15 Qs

Chapter 8 Week 1

Chapter 8 Week 1

9th - 12th Grade

11 Qs

Q1 W1 M1 PRE-TEST

Q1 W1 M1 PRE-TEST

10th Grade

15 Qs

Computer Security

Computer Security

8th - 10th Grade

10 Qs

3rd week g9 summative

3rd week g9 summative

7th - 12th Grade

15 Qs

If/Else

If/Else

Assessment

Quiz

Computers

9th - 12th Grade

Practice Problem

Hard

Used 161+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

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.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?