Practice Challenges for Fun
This lesson has some challenging problems for you to solve.
We'll cover the following...
We'll cover the following...
Quiz
Attempt the following quiz questions:
Consider the following if statement:
if (x > 2)
{
   if (y > 2)
   {
      z = x + y;
      System.out.println("z is " + z);
   }
}
else
   System.out.println("x is " + x);
1.
What is displayed when the values of x and y are 3 and 2, respectively?
A.
Nothing is displayed
B.
x is 2
C.
z is 7
D.
Error
1 / 3
1.
How old are the people in Group 1?
0/500
Show Answer
1 / 6
1.
What multiway if statement will decide the percentage increase of an employee’s salary based on the following merit rating scale?
  Rating     % Increase
  95 and above  5.0
  80 to 94     2.5
  Below 80    1.25
0/500
Show Answer
1 / 3
1.
Assume that the int variable sumCode has been assigned a value. Rewrite the following multiway if statement as a switch statement:
if (sumCode == 1)
   sum = sum + 2.5;
else if (sumCode == 2)
   sum = sum + 5.0;
else if (sumCode == 3)
   sum = sum + 7.5;
else if (sumCode == 4)
   sum = sum + 10.0;
else
   sum = 0;
0/500
Show Answer
1 / 3
Challenge 1: Read an answer to a question and react to it
Write some code that displays a question whose answer is yes or no. Read the answer as a string.
- If the answer is
yes, display 
You answered YES!. - If the answer is no, display 
You answered NO!. - If the answer is longer than three characters, display 
Your answer is too long!. - If the answer has three or fewer characters, but is not