Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to take command line inputs

 
akila sekaran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This program is supposed to take in inputs but this ones printing just the default print statements..
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Campbell Ritchie. You are 99 years old!

Worked perfectly
What are you writing at the command-line?
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you run it? From a shell window or from an IDE?


 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Output: Hello gaurang 21. You are 21 years old!

It works perfectly...


 
akila sekaran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Hello Campbell Ritchie. You are 99 years old!

Worked perfectly
What are you writing at the command-line?




i had to use the InputStreamReader to get in the values which worked fine now.. but this code posted works but jus prints without gettin any input from user..
 
Junilu Lacar
Bartender
Pie
Posts: 7320
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program is expecting the "input" to be specified on the command line, just as Campbell has shown.

If you're on Windows, you would run it this way:

C:> java Arguments Akila Sekaran 18

And it should work perfectly by giving the output:

Hello Akila Sekaran. You are 18 years old!

Please try to read the replies more carefully next time so you don't have to have multiple people telling you the same thing. Thanks.
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akila sekaran wrote: . . . i had to use the InputStreamReader to get in the values . . .
That is not how the args array works. As Junilu Lacar told you, and several other people, you need to enter those data at the command line. Not a reader of any sort.
 
Stanley Mungai
Ranch Hand
Posts: 155
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akila, If I was you I would Do:

 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not if you want command-line arguments. A BufferedReader reading from System.in might be a better way to take input generally, but the original post was specifically written to use command-line arguments.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic