• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to accept i/p's from user

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to accept i/p's from user in a command prompt?

when we want to print data to standard o/p we use system.out.print(data)
..but how do we accept data from user and store it in a variable
/*system.in()...*/ is it? or is something to do with Handler class

i am beginner pls help!
Thank's
amal
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you mean by "ips" as inputs, not a users actual IP address.
You can get input from a user by using the "Scanner" class.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are indeed looking for command line input, you could also do it this way:



You would need to provide some exception handling to go with this too, enclose your code in a try.......catch block.

Event handling which you mention is usually used to get input from a GUI (e.g. a user clicks a button), whereas this kind of system prompt input is not event driven (maybe it can be?)

Hope that's helpful


[ June 03, 2006: Message edited by: Ellie Barnes ]
 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank's ellie that helped...stephen the scanner class don't seem to appear in java doc 1.4..well how to go about with this scanner class
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amal shah:
thank's ellie that helped...stephen the scanner class don't seem to appear in java doc 1.4..well how to go about with this scanner class


The java.util.Scanner was new with Java 1.5. So if you're using 1.4 or earlier, you should use the approach outlined by Ellie.

Or you can upgrade to Java 5.0.
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Or you can upgrade to Java 5.0.

Or indeed look forward to the new java.io.Console class in Java SE 6!
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could use Jakarta Commons CLI, also.
 
No, tomorrow we rule the world! With this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic