Sometimes in our stand alone java program we need to read user input data. Below code snippet will show you how to read user input in a Java application.
-
package com.tctalk.myapp.java.src;
-
Â
-
import java.io.BufferedReader;
-
import java.io.IOException;
-
import java.io.InputStreamReader;
-
Â
-
/**
-
* ReaduserInput.java – [This code reads the user input data from command prompt]
-
*
-
* @author TechCuBeTalk.com
-
* @version 1.0
-
*/
-
public class ReaduserInput {
-
Â
-
Â
-
    // Ask the user to enter their name
-
Â
-
    // To read user input create a reader object
-
Â
-
    String userName = null;
-
Â
-
    // read the user input from command prompt by readLine() method
-
    try {
-
      userName = br.readLine();
-
    }
-
Â
-
Â
-
  }
-
Â
-
}
-
Â
Related Articles:
- JfreeChart Series-2: How to create a dynamic Pie Chart using JFreeChart library in Java  In the earlier tutorial I showed you how to create...
- How to test if a String is palindrome or not in Java? Steps to check if a given string is a Palindrome...
- How to load a properties file in Java This tutorial will explain how to access properties file through Java...
- How to create Windows executable EXE from a Java Jar Creating Windows executable EXE file from a Jar file: //...
- JfreeChart Series-1: How to create a dynamic Bar Chart using JFreeChart library in Java In Java creating any graph or chart like bar chart...
- File upload to BLOB field and display attachment dialog box Sometimes a developer needs to provide the feature in their...
- Step by step guide to create Singleton design pattern with Java Singleton design pattern is a kind of design pattern...
- creating non duplicate array from duplicate array in Java This example helps you to generate a fresh and non...
