This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input in Java, Simplest way

 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its surprising that after reading almost the whole book, . . . Guys Is there any simplest way to get the input in java, such that I can add 2 strings, numbers by taking command line input from user.
There is only one way I know,
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

This clicks me as somewhat odd way of taking input. Guys I have recently moved from C/C++ to Java, and I was expecting the input taking mechanism to be butterly simple, but the above statement horrified me badly. We learn in 2-3rd chapter in C/C++ "How to take input" and in Java why is it such lately introduced in almost all the books?


Thanks
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are millions of ways of getting input. For input from the command line you could use the commandline arguments (main(String[] args), your approach but I would recommend you to look at the Console class which was introduced in java 6.
1 trapdoor: not all environments can supply a Console, for instance the Netbeans IDE.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a Scanner addict myself.... I find it's pretty easy. Here's the API.

Janeice
 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replies man, but in general Java books, why they are covered way after traversal of key concepts, thats still unknown to my limited intelligence.
thanks again, scanner one is really a cool one!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic