package conditionals; import java.util.Scanner; public class Condition { public static void main(String[] args) { Scanner scan = new Scanner(System.in); /* nested if-else */ boolean condition1 = true; boolean condition2 = false; if (condition1) { // nesting lets us add code appropriate for condition1 // whichever way condition2 comes out. System.out.println("condition 1 is true"); // then check condition2 if (condition2) { System.out.println("both are true"); } else { System.out.println("1 but not 2"); } } else { System.out.println("condition 1 is false"); if (condition2) { System.out.println("2 but not 1"); } else { System.out.println("both false"); } } System.out.println(); System.out.println("What color shall we paint the roses?"); String roseColor = scan.next(); // using .equals instead of == for Strings if (roseColor.equals("blue")) { System.out.println("Blue roses do not occur in nature."); } else if (roseColor.equals("green")) { System.out.println("Green roses are trippy."); } else if (roseColor.equals("aquamarine")) { System.out.println("Aquamarine roses are pretty."); } else { System.out.println("Not blue not green not aquamarine."); } // "blue" is a String object // this way around is often safer, can't get a null pointer if ("blue".equals(roseColor)) { System.out.println("Blue roses do not occur in nature."); } else if ("green".equals(roseColor)) { System.out.println("Green roses are trippy."); } else if ("aquamarine".equals(roseColor)) { System.out.println("Aquamarine roses are pretty."); } else { System.out.println("Not blue not green not aquamarine."); } } }