Getting a Input from a user

Pre-requisite:

1.Java installed.

Step 1:Write a Java code to get the input from a user and and display back again.

File:getin.java

import java.io.*;
class getin
{
public static void main(String ar[])
{
String name=””;
System.out.println(”Enter your data to display”);
BufferedReader datain=new BufferedReader(new InputStreamReader(System.in));
try
{
name=datain.readLine();
System.out.println(”The value you have entered is ” +name);
}
catch(IOException e)
{
System.out.println(”Error Occured”);
}
}
}

Sample Output:
Enter your data to display
Nice Time
The value you have entered is Nice Time

Feel free to share your comments.

Advertisements