+ 3
Scanner to int
How do i convert scanner to int? I want user input in my method args but is says that scanner cant be converted to int. Please help.
3 ответов
+ 12
This code allocates an integer and scanner, followed by reading the integer from the scanner.
int number;
Scanner scan = new Scanner(System.in);
number = scan.nextInt();
+ 5
you could also do this 👍
int input = new Scanner(System.in).nextInt();
+ 1
or
int num;
Scanner sc = new Scanner(System.in)
num = Integer.parseInt(sc.next());