File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Input From Console Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Input From Console" Watch "Input From Console" New topic

Input From Console

aishwarya lakshmi

Joined: Nov 18, 2008
Posts: 20
Could you please let me know how to get the input from console for adding two number..

The output sould be like
Enter the first number : 5

Enter the sec number : 6

Total = 11
First it should ask for 1st number and then sec number as i mentioned above..

I tried with reader and stream and scanner.. But its fecting all value... ie("Enter the first number ")...

Can any one helps me to achive this..

Many thanks
Adam LaFaye

Joined: Apr 14, 2009
Posts: 21
can you explain a little more about what your are doing??? are using a java ide? command line? can you post your .java file?
aishwarya lakshmi

Joined: Nov 18, 2008
Posts: 20
I am not using IDE , I am running in Command prompt...

I need get the value from console.....I dont want to get the value from comand line argument..

For adding Two number.. I want to Get the input number one by one....
First I need to display the "Enter first number".. Once after entering first number,
I need to display "Enter second number" Once after entering second number, I need the total... As i mentioned before...

I C Language we will use printf and scanf.... Hoe to aschive it in java.....

Adam LaFaye

Joined: Apr 14, 2009
Posts: 21
Try System.out.println("say what you have to say " + obj);
Sambhavi Balasubramaniam

Joined: Mar 05, 2009
Posts: 7

Give System.out.println to display whatever you want to be shown on screen.

Take your input variable through and store it in a BufferedReader object. Then readLine that BufferedReader and assign it to an int variable (for your case).

This will meet your requirement. Hope this helps!

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
Better to use the methods of Scanner. There are several methods called nextXXX(); one of those will be helpful.
I agree. Here's the link:
subject: Input From Console
It's not a secret anymore!