0

How to take input ?

which keyword is similar in java keyword like scanf,cin of c and c++ languages? how it is used?

13th Nov 2016, 4:47 AM
Prafull Singh
Prafull Singh - avatar
2 Answers
+ 1
There are few different ways: public class ConsoleReadingDemo { public static void main(String[] args) { // ==== BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter user name : "); String username = null; try { username = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } System.out.println("You entered : " + username); // ===== In Java 5, Java.util.Scanner is used for this purpose. Scanner in = new Scanner(System.in); System.out.print("Please enter user name : "); username = in.nextLine(); System.out.println("You entered : " + username); // ====== Java 6 Console console = System.console(); username = console.readLine("Please enter user name : "); System.out.println("You entered : " + username); } } http://stackoverflow.com/questions/4644415/java-how-to-get-input-from-system-console
13th Nov 2016, 6:08 AM
Ivan G
Ivan G - avatar
0
import java.util.Scanner; class ....{ ...main(String args[]){ Scanner stdin = new Scanner(System.in); stdin.nextInt(); you import the scanner class you make a new Scanner object here I called it stdin (standard input).Then you cal the method you want here I asked for an integer.You may also use stdin.nextDouble() ,or for strings
13th Nov 2016, 4:58 AM
Nissan
Nissan - avatar