Chapter 4 - Decision making. In this chapter we will: discuss the use of decision making in computer programming, describe the use of the Java if and switch statements, describe the use of Boolean expressions in Java if statements, discuss the use of integer selector variables in Java switch statements.
Chapter Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N Kamin, D Mickunas, E Reingold Chapter Preview In this chapter we will: • discuss the use of decision making in computer programming • describe the use of the Java if and switch statements • describe the use of Boolean expressions in Java if statements • discuss the use of integer selector variables in Java switch statements if Statement • Ensures that a statement is executed only when a condition is true • Conditions typically involve comparison of variables or quantities for equality or inequality • Example: if (age >= 18) out.println(“You are eligible to vote.”); Relational Operators < < less than > > greater than = greater than or equal to = == equal to != not equal to if Statement with Optional else • An if statement may have an optional else clause that will only be executed when the condition is false • Example: if (wages > greater than