aspose file tools*
The moose likes Beginning Java and the fly likes Change Program (How can I get two inputs) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Change Program (How can I get two inputs)" Watch "Change Program (How can I get two inputs)" New topic
Author

Change Program (How can I get two inputs)

Juan Sifuentes
Greenhorn

Joined: Sep 02, 2008
Posts: 6
I am making a simple change program. I need to get two inputs (ammount due and payed). I am using notepad and command promt.
I learned to get 1 input by writing this in notepad

"String s = args [0];"

and I run my program and enter single input in the command prompt by entering

"java (Class name) (input statement)"

What code can I used to get one input then another?
I want to ask

Ammount Due?
(enter 1st input)
Ammount Payed?
(enter 2nd input)
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


"String s = args [0];"

and I run my program and enter single input in the command prompt by entering

"java (Class name) (input statement)"


Juan,

command line argumemts are not limited to one. you can use more than one command line arguments to Java program.




Also if you need to ask for input and user needs to enter. then have look at Scanner API
Juan Sifuentes
Greenhorn

Joined: Sep 02, 2008
Posts: 6
Thanks, that helps.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Juan Sifuentes wrote:I want to ask

Ammount Due?
(enter 1st input)
Ammount Payed?
(enter 2nd input)

Check out System.console(), in particular the readLine() methods. Keep in mind that System.console() can return null, so check against that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39818
    
  28
The Scanner class is probably easier to use than Console.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change Program (How can I get two inputs)