get user input from command line
I am just trying to get user input from the
command line in response to output to user.
I have tried using the readLine() method but
it seems to be deprecated and I'm not being
allowed to use it.
What gives.
I feel pretty stupid here.
This should be simple
Here is a solution you may want to consider:
Using the TextReader class, that you can get at:
http://www.cs.arizona.edu/people/reges/
by clicking on TextReader on the sidemenu. Then you could do this:
TextReader console = new TextReader(System.in);
System.out.print("What is your name? ");
String name = console.readLine();
System.out.print("Give me two positive numbers, " + name + " --> ");
double x = console.readDouble();
double y = console.readDouble();
System.out.println(x + " to the " + y + " power = " + Math.pow(x, y));
System.out.print("Give me a positive integer, " + name + " --> ");
int n = console.readInt();
System.out.println("2 to the " + n + " = " + (int)Math.pow(2, n));
This example is in the documentation for this class. The documentation is here:
http://www.cs.arizona.edu/people/reges/teachers/TextReader.html
I really like the TextReader class. I dont know what readLine() method you are using, but TextReader has a readLine(), and it works very well. Hope this helps.
Good Luck
There are several readLine() methods. You are using one of the deprecated ones. (look up
readLine in the API index).
Go with the simplest and best solution-- the first reply to your question. BufferedRead.readLine() is not deprecated, is standard Java, and is far simpler than the other solutions that people are suggesting to you.
Thanks to all of you.
I have not been watching the replies to
this question because I soon figured out
the problem.
Thanks for all suggestions.
The only resolution I could find was to reward
the first respondant the bucks.
Thanks.
Scott