Java User Input

Java User Input

Java User Input: To pass data to a running Java program many ways exists like through

1. Command-line arguments
2. Keyboard input
3. GUI

Here 2nd style is chosen to illustrate as it is easy to write to a Learner but in realtime the 3rd one is used.

In Java User Input Mangoes name, rate and number are taken and their cost is evaluated.

Java User InputOutput Screenshot on Java User Input

Scanner scan1 = new Scanner(; gets connected automatically to underlying keyboard reading mechanism of OS. This is passed to Scanner constructor to link with. When linked, the Scanner object scan1 reads from Java User Input. Methods used are nextLine(), nextDouble() and nextInt() returning a string, a double value and a int value that can be used in coding for arithmetic manipulations.

For more command on keyboard input, read the three styles using different classes and different I/O Streams.

1. Using DataInputStream (
2. Using BufferedReader (
3. Using Scanner