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

[319 byte] By [fissionchips] at [2007-9-26 2:08:44]
# 1
BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );String str = in.readLine();
parthasarkar at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...
# 2
I dont know wheather readLine is deprecated or not.but it works very fine. try this :BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );String str = in.readLine();
bontz at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...
# 3
I think you must thrown an IOException. So, just try this public static void main (String args []) throws Exception {...... }
derik0920 at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...
# 4
> I dont know wheather readLine is deprecated or not.butthe one in BufferedReader is not deprecated. the readLine() methods in ObjectInputStream and DataInputStream are deprecated.i think the original poster was referring to DataInputSteam.
parthasarkar at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...
# 5

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

armandfcdx at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...
# 6

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.

blaine.simpson at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...
# 7

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

fissionchips at 2007-6-29 8:57:36 > top of Java-index,Archived Forums,Java Programming...