Search⌘ K
AI Features

Practice Challenges for Fun

Explore how to implement decision-making in Java by working through practical challenges that use if statements, comparisons, and boolean expressions. This lesson helps you gain confidence in writing Java code to compare values, test conditions, and adjust variables based on criteria.

Quiz

Attempt the following quiz questions

Technical Quiz
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. Multi-select

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;

1 / 2

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


1 / 3

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


1 / 8

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


1 / 8
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 ...