| Author |
Input From Console
|
aishwarya lakshmi
Greenhorn
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
lakshmi
|
 |
Adam LaFaye
Greenhorn
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
Greenhorn
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
Greenhorn
Joined: Apr 14, 2009
Posts: 21
|
|
|
Try System.out.println("say what you have to say " + obj);
|
 |
Sambhavi Balasubramaniam
Greenhorn
Joined: Mar 05, 2009
Posts: 7
|
|
Lakshmi,
Give System.out.println to display whatever you want to be shown on screen.
Take your input variable through System.in 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!
Cheers,
Sam
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
|
Better to use the methods of Scanner. There are several methods called nextXXX(); one of those will be helpful.
|
 |
 |
|
|
subject: Input From Console
|
|
|