How to get user input as integers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to get user input as integers

I could not use integers in the scanner example given. Please tell me how to

8th Nov 2016, 7:50 AM
Devansh Das
Devansh Das - avatar
2 Answers
+ 2
import java.util.Scanner; public class Main{ private static Scanner sc; public static void main (String[] arts){ Scanner sc = new Scanner(System.in); int x;//this is to initilized the varible location; System.out.println("Enter a number: "); x = sc.nextInt();//the nextInt is used to store interger varibles System.out.println(x); } }
8th Nov 2016, 8:30 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
+ 1
Scanner sc=new Scanner(System.in); System.out.println("input plzz"); int a=sc.nextInt(); // taking input as integer.
8th Nov 2016, 8:08 AM
Gaurav Aggarwal
Gaurav Aggarwal - avatar