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"); } } }
2 Respuestas
+ 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)
{
....
0
thanks