• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Input in Java, Simplest way

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic