how to get user input | Sololearn: Learn to code for FREE!


how to get user input

9/14/2016 3:29:03 PM


3 Answers

New Answer


Import the Scanner package: import java.util.Scanner; To use it: Scanner sc = new Scanner(; System.out.println(sc.nextLine()); You can also use sc.nextInt(), sc.nextDouble(), etc. to scan a number rather than a string.


Use scanner(Maybe U can try to use Google)


There are many methods to get user input : 1. Using scanner class (as explained by Zen) 2. Using bufferedreader : import*; class demo { public static void main(String args[]) throws IOException // create bufferedreader object : Bufferedreader ob = new Bufferedreader( new InputStreamReader(; int a = Integer.parseInt(ob.readLine()); 3. using parameter window : Note : this method runs only in BlueJ class demo2 { void main (int n) Hope u find this useful !!