Pittsburgh Business Daily

How does Java take in values from person?

I know that C++ takes in values from a person typing on a keyboard with cin for numerical data and getline(cin, variable) for strings, but how does Java take in values? I mean, what is Java's equivalent of cin, and how do I put that value into a variable? Thanks!

Public Comments

  1. Java uses InputStreams and OutputStreams. These are essentially low-level wrappers around a stream of data that you can read and write to. You can add wrappers around that for various functionality. You want something like: BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = in.readLine(); Note that readLine() can return null on an end of stream and throw an IOException if an error occurs.
Powered by Yahoo! Answers