• 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 and output

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me in asking the user to enter text, an int, long etc. That is , how do we accept input from the user. The input can be of any data type., including objects. Is there a mechanism of cin and cout like in c++. In fact, I want to teach my students asking for input in their programs like the way C++ does. How can we do the sam in JFc and AWT? Please help me as fast as U can.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the weakest part of my Java programming is the I/O. In fact there are huge books about this subject which I have not been able to read up on.
I'm not sure if there is a class the is advance enough to return the correct data type (String, int, float) that is needed....
Here is how I would read in an integer:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String someStr = null;
int someInt = 0;
try {
someStr = in.readLine();
someInt = Integer.parseInt(someStr, 10);
}
catch (IOException e) { }
I guess you'd have to do this for all data types if there are no other ways.
 
reply
    Bookmark Topic Watch Topic
  • New Topic