Pages

Wait user input in java

Complete source code below will show you, how to wait for user input in command prompt.
Input is a line of text.

**********************************************************************
COMPLETE SOURCE CODE FOR : WaitUserInput.java
**********************************************************************


import java.util.Scanner;

public class WaitUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your name ?)
System.out.println("What is your name ?");

//WAIT FOR USER INPUT
//After user put it's name, he or she must press 'Enter'
//After user press 'Enter', all the input contents will read into 'myName'
String myName=readUserInput.nextLine();

//Print what it store in myName
System.out.println(myName);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************
Related Posts Plugin for WordPress, Blogger...