+ 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.

28th Jun 2018, 8:51 PM
Terraria_master7
Terraria_master7 - avatar
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();
28th Jun 2018, 9:23 PM
John Wells
John Wells - avatar
+ 5
you could also do this 👍 int input = new Scanner(System.in).nextInt();
29th Jun 2018, 8:29 AM
D_Stark
D_Stark - avatar
+ 1
or int num; Scanner sc = new Scanner(System.in) num = Integer.parseInt(sc.next());
29th Jun 2018, 8:49 AM
Siphelele Sanele Mndzebele
Siphelele Sanele Mndzebele - avatar