Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input From Console

 
aishwarya lakshmi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try System.out.println("say what you have to say " + obj);
 
Sambhavi Balasubramaniam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better to use the methods of Scanner. There are several methods called nextXXX(); one of those will be helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic