| Author |
Scanner string parameters
|
Austin smit
Greenhorn
Joined: Nov 04, 2008
Posts: 6
|
|
I need help with making a users input (string) to be able to be upper case or lower case of Y. So if they answer with yes, Y, y, yippee, Yippee, it will play again no matter what, else game ends. so could i use charAt(0); and how because i would need to convert it back to a string or ....
|
 |
Thomas Young
Greenhorn
Joined: Jul 17, 2008
Posts: 29
|
|
Hi Austin, I am not too sure what you are trying to explain here, but could you try something along the lines of: if(stringname.toUpperCase().charAt(0) =="Y") { // do this. } You could assign a second variable to whatever stringname is so that you can preserve the data in "stringname" or just a char to the first char of "stringname" Not 100% sure this is the best way to do things, but a suggestion. Regards, TY.
|
 |
Thomas Young
Greenhorn
Joined: Jul 17, 2008
Posts: 29
|
|
wait, I think both sides of that condition need to be chars for what I suggested to work. ignore my crappy suggestion.
|
 |
Austin smit
Greenhorn
Joined: Nov 04, 2008
Posts: 6
|
|
|
Okay, A new game should begin if the user's response starts with a lower or upper case Y. For example, answer such as "y", "Y", "yes", "YES", "Yes", "Yippee" all indicate that the user wants to play again. How can one make the users input be uppercase or lower case and be the first letter. Thats why i asked about charAt(0); but then i would need to convert it to a string for the if/else statement which i cannot figure out.
|
 |
Kartik Rao
Greenhorn
Joined: Nov 04, 2008
Posts: 3
|
|
Try startsWith Cheers
|
CSM, SCJP, SCJD (In Progress...)
|
 |
Bill Shirley
Ranch Hand
Joined: Nov 08, 2007
Posts: 457
|
|
Familiarize yourself with the String API. You will use it over and over, and knowing it well will benefit you.
|
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
|
 |
 |
|
|
subject: Scanner string parameters
|
|
|