+ 3

Is there any other way to take input from user?

18th Dec 2016, 10:00 AM
Mit Patel
Mit Patel - avatar
4 Answers
+ 3
You have the 'Scanner' and the 'JOptionPane' Classes
18th Dec 2016, 12:33 PM
Javier Calvo
Javier Calvo - avatar
+ 3
I know 4 ways out of which 1 is outdated. Outdated one is:- int a=System.in.read(); The other 3 ways are:- 1. Scanner class. 2. BufferedReader class 3. This method can only be applied when we are compiling and running the program through CMD. For example:- If the name of the file is sum.java in which there is a program that inputs 2 numbers and print their sum and the file is stored in D drive, then the codes of the program are:- class sum { public static void main(String args[]) { int a=Integer.parseInt(args[0]); int b=Integer.parseInt(args[1]); int c=a+b; System.out.print("The sum is "+c); /*You can also apply try/catch.*/ } } And the statements in CMD are as follows. D:/javac sum.java D:/java sum 2 3 The sum is 5
21st Dec 2016, 7:22 AM
Sarthak Mathur
Sarthak Mathur - avatar
+ 1
Yes you could also use JOptionPane
13th Jan 2017, 5:49 PM
Crispin
Crispin - avatar
0
Agree to @Sarthak. You can also use the DataInputStream class. It's similar to the Scanner class.
24th Dec 2016, 10:41 AM
Siddharth Bose
Siddharth Bose - avatar