Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cin.getline for java

 
Joachim Milsom
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.in
Rene
 
Joachim Milsom
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahem, readLine() *is* returning a String...
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic