0

What are the mistakes here?

import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); System.out.println("your age is="+myVar.nextInt()); if(myVar>=18){ System.out.println("Too young"); } else{ System.out.println("Welcome"); } } }

23rd Dec 2017, 5:52 AM
Hardik Sonkar
Hardik Sonkar - avatar
2 Answers
+ 3
myVar is not an integer rather it is a scanner reference so you should not use it in your if statement to compare it with an integer value. int age = myVar.nextInt(); if(age >= 18) { ....
23rd Dec 2017, 5:59 AM
Da' BO$
Da' BO$ - avatar
0
thanks
23rd Dec 2017, 6:01 AM
Hardik Sonkar
Hardik Sonkar - avatar