AI Features

Practice Challenges for Fun

In this lesson, we will practice what we have learned about if statements by taking the following challenges.

Quiz

Attempt the following quiz questions

1

Which Java statement(s) assign the larger of two given integers, n1 and n2, to the variable larger. You can select multiple correct answers.

A)
if (n1 < n2)
   larger = n2;
else
   larger = n1;
B)
larger = n1; 
if (n1 < n2) 
   larger = n2;
C)
if (n1 > n2)
   larger = n2;
else
   larger = n1;
D)
if (n1 < n2)
   larger = n1;
else
   larger = n2;
Question 1 of 20 attempted

Evaluate each of the following expressions by hand, where x, y, and z contain 1, 3, and 5, respectively

1

(x == y) || (y > z)

A)

True

B)

False

Question 1 of 30 attempted

Consider the boolean variables x, y, and z. What is the value of the expression (x && y) || !z in each of the following cases?

1

When x, y, and z are true, (x && y) || !z is

A)

True

B)

False

Question 1 of 80 attempted

Consider the boolean variables x, y, and z. What is the value of the expression !(x && (y || !z)) in each of the following cases?

1

When x, y, and z are true, !(x && (y || !z)) is

A)

True

B)

False

Question 1 of 80 attempted
1.

How would you compare two variables having the same primitive type and how would you compare two variables having the same object type.

Show Answer
1 / 2
1.

Write an assignment statement that is equivalent to the if-else statement shown below:

int count;
. . .
boolean result;
if (count % 10 == 0)
   result = true;
else 
   result = false;
Show Answer
1 / 6

Challenge 1: Compare integers

Add Java statements to the following program that compares two given integers, n1 and n2, ...

Ask