On a piece of notebook paper, please answer for both Problem 1A-C and 2A-C.
Problem #1: Determine if a number is between 0 and 25, 26 and 50, or greater than 50.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | var x = 75; if(x > 50) { println(x + ">50!"); } else if(x > 25) { println(x + ">25!"); } else { println(x + "<=25!"); } // Output: ___________________ var x = 75; if(x > 25) { println(x + ">25!"); } else if(x > 50) { println(x + ">50!"); } else { println(x + "<=25!"); } // Output: ___________________ |
Although the program syntax is correct, what is the problem with the second block of code?
Problem #2: If a number is 5, change it to 6. If a number is 6, change it to 5.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var x = 5; println("x is now: " + x); if (x == 5) { x = 6; } if (x == 6) { x = 5; } println("x is now: " + x); // Output: _______________ var x = 5; println("x is now: " + x); if (x == 5) { x = 6; } else if (x == 6) { x = 5; } println("x is now: " + x); // Output: _______________ |
Although the program syntax is correct, what is the problem with the first block of code?
Go Back to Conditionals 3: Else If Statements