• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

input and output

 
ravi rajasekhar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Ron Pac
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic