+ 1

Where did I make a mistake?

I want to get an integer Userinput that if it's lower than 18 prints a line with a string other then when the Userinput is higher than 18 Here's the code: import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner Age = new Scanner(System.in); if (Age < 18) { System.out.println("Goodbye"); } else { System.out.println("Welcome"); } } }

7th Jan 2017, 1:36 AM
datweirdboii
datweirdboii - avatar
2 Respostas
+ 6
You're missing a step. You forgot to create a variable that can hold the value of the user input and since you want an int you would type something like: int x = age.nextInt(); After the creation of the scanner and since age is a variable the proper convention is to make it lowercase. After making these changes, change age in your if statements to x, since you're checking if the user's input (x) is less than 18. Hope that helped, and good luck in your future programs
7th Jan 2017, 1:47 AM
Earl Chukwu
Earl Chukwu - avatar
+ 2
import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner input = new Scanner(System.in); int age; age = input.nextInt(); if (age < 18) { System.out.println("Goodbye"); } else { System.out.println("Welcome"); } } } You have to remember to actually a) take in the users input, you just created the scanner and b) store that response so that you can utilize it later.
9th Jan 2017, 6:52 AM
Spyke Olsen
Spyke Olsen - avatar