CS 111A Lecture Notes - Decision Structures - Chapter 3

if-else structures

Relational Operators

Here's a program uses the above structures to calculate interest on an investment

In-class exercise #1: Write a program to input the names and ages of 2 people. Then output which name is longer, and if the ages are the same or not.

NamesAndAges.java: Solution to above in-class exercise

Nested and Multi-Way If-Statements

Logical Operators

Boolean Expressions and Variables

Switch Statements

In-class exercise #4: write a program to input the user's 5-digit ZIP code, and output which city they live in from the following table. Use a switch statement to do it.

First 3 digits of ZIP code City
900 or 901 Los Angeles (and area)
921 San Diego (and area)
937 Fresno (and area)
941 San Francisco
942 Sacramento
946 Oakland (and area)

ZipCodes.java: Solution to in-class exercise #4 to determine city from ZIP code, using switch

Return to CS 111A page