Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is equivalent to Cin in Java?

Status
Not open for further replies.

Sidro

MIS
Sep 28, 2002
197
US
Hi,
How do I read an input from the user and store it into a variable? Example in C++ I would do it like this.

int A;
cout<<&quot;Enter some number.&quot;;
cin>>A;

How would I do this in java? thanks in advance.
 
Here is a code sample to do cin in JAVA.

Code:
import java.io.*;

public class ConsoleReader
{
	public static void main(String[] args)
	{

		BufferedReader readConsole = new BufferedReader(new InputStreamReader(System.in));
		System.out.print(&quot;Enter some number: &quot;);
		String someNumber = null;
		try
		{
			someNumber = readConsole.readLine();

		}
		catch(IOException e)
		{
			System.out.println( e );
		}
		System.out.println(&quot;The Number you entered is &quot; + someNumber);
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top