- yes or no?
- Yes or No!
- No E Allowed
- Repetition
- PigLatin I
- Pig Latin II
- Pig Latin III
- Pig Latin Finale
Java String Resources:
yes or no?
Collapse Content
Show Content
You're working on an interactive text-based menu that asks the user Yes-or-No questions. Users are supposed to reply with just 'y' or 'n', but sometimes they add other characters, such as "yes" or "no".
Complete a method that checks the first character of a String and returns an String according to the following table:
first character of input | return following String |
---|---|
'y' | 1 |
'n' | 0 |
other character | -1 |
(Note: all input will be lowercase.)
Challenge
Return a number based on the given input String as in the above table.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
David
Apr 6, 4:11 PMAdmin does the Java compiler version used by learneroo permit using Strings in switch statements? I found in stackflow that Java 7 does not allow this.
Thanks and Best regards.
Learneroo
Apr 6, 4:15 PMWe use Java 7 which does allow it. This challenge can use characters which could always be used.
Joshua
Aug 26, 8:45 PMThis is getting kind of frustrating. I'm not sure what I'm doing wrong no matter what i do there is always an incompatibility in data types. Either I need a string and I have a character or I have a character and I need a string.
Its saying that my char shown to be defined as a character is a string in the if statement. How does that make any kind of sense? Somebody help me please...
Joshua
Aug 27, 3:27 PMNevermind... Forgot that characters require single quotes.
thales
Jul 17, 7:12 AMmy solution:
my code