package conditionals; import java.util.Scanner; public class IfExamples { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = 10; int b = 778899; System.out.println("What's your lucky number?"); int userFave = scan.nextInt(); boolean aIsBigger = a > userFave; boolean bIsBigger = userFave < b; // if with boolean variable as condition (false) if (aIsBigger) { System.out.println("Seems a was bigger, weird."); } // if with boolean expression as condition (false) if (a > userFave) { System.out.println("Second try: Seems a was bigger, weird."); } // if with boolean variable as condition (true) if (bIsBigger) { System.out.println("b was bigger."); } // if with boolean expression as condition (true) if (userFave < b) { System.out.println("Second try: b was bigger."); } double ponyPrice = 2000000; System.out.println("How much cash do you have?"); double myCash = scan.nextDouble(); // if with else if (myCash >= ponyPrice) { System.out.println("OMG PWNIES!!!"); } else { System.out.println("You can't afford a pony."); } 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."); } // "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."); } } }