 # Decisions with if statements. Simple If Statements if (age < 18) g.drawString(You may not vote., 50, 50); Evaluating a single expression.

## Presentation on theme: "Decisions with if statements. Simple If Statements if (age < 18) g.drawString(You may not vote., 50, 50); Evaluating a single expression."— Presentation transcript:

Decisions with if statements

Simple If Statements if (age < 18) g.drawString(You may not vote., 50, 50); Evaluating a single expression

Simple If Statements if (age > 18) g.drawString(You may vote., 50, 50); Evaluating a single expression

Simple If Statements if (age >= 18) g.drawString(You may vote., 50, 50); Evaluating a single expression

Simple If Statements if (age != 16) g.drawString(You are not sixteen years old., 50, 50); Evaluating a single expression

Simple If Statements if (age == 16) g.drawString(You are sixteen years old., 50, 50); Evaluating a single expression

Logical Opereators >Greater than <Less than ==Equal to !=Not equal to <=Less than or equal to >=Greater than or equal to

Equal Signs =This is used to assign values to variables. int sliderValue = 0; ==This is used to compare values. if (age == 16)

Multiple Comparisons if (age >= 21 && age < 65) g.drawString(You may be an airline pilot., 50, 50); Evaluating multiple expressions

Multiple Comparisons if (age = 65) g.drawString(You may not be an airline pilot., 50, 50); Evaluating multiple expressions

If-Else Statements if (age < 18) g.drawString(You may not vote., 50, 50); else g.drawString(You may vote., 50, 50); Using Else with If statements

If-Else Statements if (age = 65) g.drawString(You may not be an airline pilot., 50, 50); else g.drawString(You may be an airline pilot., 50, 50); Using Else with If statements

Grouping Statements if (age < 18) { g.drawString(You may not vote., 50, 50); g.drawString(You may not serve in the military., 50, 50); g.drawString(You may not sign business contracts., 50, 50); } else { g.drawString(You may vote., 50, 50); g.drawString(You may serve in the military., 50, 50); g.drawString(You may sign business contracts., 50, 50); } Grouping statements with braces

Similar presentations