0
What is the problem of this code?
import java.util.Scanner; public class remon{ public static void main(String [] args){ Scanner r= new Scanner(System.in); if(r < 16) { System.out.println("Too young"); } else { System.out.println("Mature"); } } }
3 Answers
+ 8
r is defined but you can't compare a scanner to an int.
r is a SCANNER.
You must use the scanner to take user input.
int input = r.nextInt();
// nextInt will grab the next integer in the input
if(input < 17){
// Now you can do your thing
}
0
yupz
I have come out of the problem.
0
import java.util.Scanner;
public class remon{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
int r = input.nextInt();
if(r < 16)
{
System.out.println("Too young");
}
else
{
System.out.println("Mature");
}
}
}