Selection Statements
Last modified Sunday, 07-Jul-2024 16:06:39 UTC.
Exercises
- Do if and if-else true and false blocks have
to be compound statements?
- What is the hanging else problem?
- Write an if-else statement using a nice formating style. Now write it
again in another nice style. Now write it with bad formating, and feel
bad about doing it.
- List all the reserved keywords of Java that are used in if-else and
switch statements.
Exam Style Questions
- What is the effect of the break statement in a switch
statement?
- Write a program that inputs a percentage, then prints out either
pass or fail depending on whether or not the
percentage is greater or equal to 50%.
- What is the output from this program
Program to be announced
- Write a switch statement that increments, decrements, or
zeroizes the int variable mover, depending on the
character in the choice variable - one of 'I', 'i', 'D', 'd',
'Z', or 'z', indicating the first letter of the operation. If the
character is none of those, print an error message.