/** * Write a description of class ConditionalExample here. * * @author (your name) * @version (a version number or a date) */ public class ConditionalExample { public static void main(String[] args) { int age = 20; //if statement if (age < 25) { System.out.println("Sorry, you can't rent a car."); } //if-else statement if (age >= 18) { System.out.println("You better get out there and vote!"); } else { System.out.println("Sorry, you can't vote yet."); } //if-elseif-elseif... if (age == 18) { System.out.println("Feshman"); } else if (age == 19) { System.out.println("Sophmore"); } else if (age == 20) { System.out.println("Junior"); } else if (age == 21) { System.out.println("Senior"); } else { System.out.println("Who knows"); } //switch statement equivalent to the above if-elseif statement switch (age) { case 18: System.out.println("Freshman"); break; case 19: System.out.println("Sophmore"); break; case 20: System.out.println("Junior"); break; case 21: System.out.println("Senior"); break; default: System.out.println("Who knos"); break; } //more complex conditions age = 30; if (age >= 25 && age < 35) { System.out.println("You can rent a car, but you can't be president."); } age = 68; if (age < 8 || age > 65) { System.out.println("You can probably get discounts at restaurants."); } } }