import java.util.Scanner; public class decisions { public static void main(String[] args) { boolean cold = false; int temp; char rain; Scanner kb = new Scanner(System.in); int age; System.out.print("enter temp: "); temp = kb.nextInt(); if (temp < 40) cold = true; System.out.print("raining? (y/n) "); rain = kb.next().charAt(0); if (temp < 60 && rain == 'y') cold = true; if (!cold) System.out.println("it's getting hot in here"); else System.out.println("it's cold"); cold = false; System.out.print("enter your age: "); age = kb.nextInt(); if (cold && 23 < 500%10 || age >= 15) { System.out.println("true"); if (age >= 18) { System.out.println("vote"); if (age >= 21) { System.out.println("let's party"); } if (age >= 16) { System.out.println("drive"); System.out.println("be careful"); } else { System.out.println("baby"); System.out.println("whatever"); } } else System.out.println("broken"); } // COMPARING STRINGS String s1 = "Wednesday"; String s2 = "wednesday"; if (s1 == s2) System.out.println("s1 s2 same"); String s3 = "Wednesday"; if (s1 == s3) // true if refer to same exact place in memory System.out.println("s1 s3 same object in memory"); // maybe s3 = new String("Wednesday"); if (s1 == s3) // true if refer to same exact place in memory System.out.println("s1 s3 same object"); // not same object String s4 = "Wed"; s4 = s4 + "nesday"; if (s1 != s4) // true if refer to same exact place in memory System.out.println("s1 s4 not same object"); // not same object if (s1.equals(s2)) // true if contain same exact characters System.out.println("s1 equals s2"); if (s1.equals(s3)) System.out.println("s1 equals s3"); if (s1.equals(s4)) System.out.println("s1 equals s4"); if (s1.equalsIgnoreCase(s2)) // ignoring capitalization version System.out.println("s1 and s2 same ignoring capitalization"); /* if (! s2.equals(s2)) // how to say not equals */ if (s1.compareTo(s2) < 0) System.out.println("s1 less than s2"); if (s1.compareToIgnoreCase(s2) > 0) System.out.println("s1 comes after s2 ignoring capitalization"); if (s1.compareTo(s2) == 0) System.out.println("s1 same as s2"); s1 = "apple"; s2 = "Pear"; if (s2.compareToIgnoreCase(s1) > 0) System.out.println(s2 + " after " + s1 + ", ignoring case"); // want to know #days in a month System.out.print("enter month by number (1-12): "); int month = kb.nextInt(); int days = 0; switch (month) { case 2: days = 28; break; case 9: case 4: case 6: case 11: days = 30; break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; default: System.out.println("invalid month"); } System.out.println("#days " + days); // this does the same thing, but uses a switch without breaks! days = 0; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days++; case 9: case 4: case 6: case 11: days += 2; case 2: days += 28; } System.out.println("#days " + days); // this does the same thing, but uses a switch without breaks! days = 28; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days++; case 9: case 4: case 6: case 11: days += 2; default: ; // do nothing } System.out.println("#days " + days); } }