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"); } } }

9th Sep 2017, 4:02 PM
Remon
Remon - avatar
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 }
9th Sep 2017, 4:43 PM
Rrestoring faith
Rrestoring faith - avatar
0
yupz I have come out of the problem.
9th Sep 2017, 4:43 PM
Remon
Remon - avatar
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"); } } }
11th Sep 2017, 4:23 AM
lacherv
lacherv - avatar