Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanner string parameters

 
Austin smit
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try startsWith



Cheers
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Familiarize yourself with the String API.

You will use it over and over, and knowing it well will benefit you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic