Decision making is an important aspect of programming. Most programs' utility is based on its ability to make certain decisions. The decision making process is based on the use of control constructs such as logical expressions, if
statements, and switch statements.
There are different types of decisions to be made and are supported in Java with different control constructs. The primary ones discussed in this chapter included the if
statement and the switch
statement.
Care must be taken with the use of these statements to avoid the pitfalls possible with their use. These include misuse of the comparison operator, not using block statements as a matter of habit, and avoiding the dangling else problem. We also examined some of the issues that can occur when working with floating point numbers.
Decision making in Java can be simple or complex. Simple and complex either-or decisions are best handled using the if then else
statement. For some of the simpler decisions, the simple if
statement...