boolean isLightGreen = true;
boolean isLightYellow = false;
if(isLightGreen){
double carSpeed = 100;
System.out.println("Drive!");
System.out.println("Speed is:" + carSpeed);
} else if(isLightYellow) {
System.out.println("Slow down.");
} else {
System.out.println("Stop.");
}
museum ticket
int ticketPrice = 10;
int age = ;
boolean isStudent = ;
if (age <= 15){
// age is less than or eaual to 15
ticketPrice = 5;
} else if(age > 60) {
ticketPrice = 5;
} else if(isStudent) {
ticketPrice = 5;
}
System.out.println(ticketPrice);
logical operators
age <= 15 || age > 60 || isStudent
if(action && romance){
System.out.println("this movie include action and romance")
if(comedy || horror){
System.out.println("this movie include comedy or horror")
}
}
switch
int passcode = ;
String coffeeType;
switch(passcode){
case 555: coffeeType = "Espresso";
break;
case 312: coffeeType = "Vanilla latte";
break;
case 629: coffeeType = "Drip coffee";
break;
default: coffeeType = "Unknown";
break;
}
System.out.println(coffeeType);