| Author |
cin.getline for java
|
Joachim Milsom
Greenhorn
Joined: Oct 30, 2002
Posts: 3
|
|
Hi, How do I read in a string entered on the keyboard in java for a simle console program??? cheers, Joe
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
System.in Rene
|
Regards, Rene Larsen
Dropbox Invite
|
 |
Joachim Milsom
Greenhorn
Joined: Oct 30, 2002
Posts: 3
|
|
BufferedReader consoleIn = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter a player:"); char name[] = String.parse(consoleIn.readLine()); I sort of knew it was System.In and I can work it out for an integer (int option = Integer.parseInt(consoleIn.readLine()) but not for a string. Any help would be great, Thanks, Joe
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
|
Ahem, readLine() *is* returning a String...
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
In case it's needed, a second ahem: String myString = consoleIn.readLine() ; In case it's not yet an oft read resource: The J2SE API Documentation In case you hadn't read it yet: Joachim, Welcome to JavaRanch!
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
 |
|
|
subject: cin.getline for java
|
|
|