0

Please explain me the mistake I made

import java.util.Scanner; public class myclass{ public static void main(String[] args){ System.out.println("Please Enter you Age"); Scanner age = new Scanner(System.in); if (age<18){ System.out.println("You are UNDERAGE"); } else { System.out.println("WELCOME"); } } } actually, I also have a doubt that I got the user input(his age) is it stored as an int in the variable age, because in the print statement then why are we adding the nextint() function??

29th Sep 2020, 10:31 AM
Arya Bamboli
Arya Bamboli - avatar
2 Respuestas
+ 2
age is a Scanner, not an int. Scanner's purpose is to get input from the user. You have to declare an int. Then assign it with age.nextInt(); https://www.sololearn.com/learn/Java/2220/
29th Sep 2020, 10:38 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Thank You So Much
1st Oct 2020, 10:34 AM
Arya Bamboli
Arya Bamboli - avatar