• Post Reply Bookmark Topic Watch Topic
  • New Topic

Command line Input

 
SonalPSPL Bagmar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to accept an Integer from user thru command line ; but i dont want to use argv[] .
Does anyone know any alternate method.
If so , please tell as soon as possible


Thanks
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about System.in?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using some version of Java pre-Java 2 v5, then take a look at the following example. If you're already using Java 2 v5, then you might prefer a different solution with the Scanner class.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you do want to use the Scanner class:



Something like that will work. Odd, doesn't save any lines of code. Just one line is shorter between the 2 versions. Why can't we just have



Oh, that's right. Everything in Java is OO so cin would have to be created somewhere just like the BufferedReader and the Scanner.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'll move this to IO and Streams.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!