File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Scanner string parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scanner string parameters" Watch "Scanner string parameters" New topic

Scanner string parameters

Austin smit

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

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.

Thomas Young

Joined: Jul 17, 2008
Posts: 29
I think both sides of that condition need to be chars for what I suggested to work.

ignore my crappy suggestion.
Austin smit

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

Joined: Nov 04, 2008
Posts: 3
Try startsWith


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 -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: Scanner string parameters
It's not a secret anymore!