+ 2
You create a Scanner object 'age' expecting that it will hold an user input. But the Scanner doesn't work that way. It's an object type, which needs its methods to get the user input: nextInt() - for integers nextLine() - for strings. 1. Since you need integer, you should use the first. 2. The age should be stored in an integer variable. So, here is how it should look like: *** // Declaring the Scanner object named 'scan' Scanner scan = new Scanner(System.in); // Prints a message for input System.out.print("Enter your age: "); /* Stores the integer into the 'age' variable by calling the method nextInt() on the scanner object 'scan'. */ int age = scan.nextInt(); if (age < 16) { System.out.println("Too young!"); } else { System.out.println("Welcome!"); } ***
28th Oct 2017, 2:08 AM
Boris Batinkov
Boris Batinkov - avatar