- 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!
Optional Node
Collapse Content
Show Content
Not only do users write whole words instead of single characters, but they sometimes use capital letters instead of lowercase ones. Also, they may leave whitespace before their actual answer.
Create a method that checks the first non-whitespace character and returns a number according to the following table.
Note: This challenge can be solved in any language, but the provided boilerplate is for Java.
first actual character of input | return following int |
---|---|
'y' or 'Y' | 1 |
'n' or 'N' | 0 |
other character | -1 |
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
mc
Dec 9, 12:53 PMTop paragraph asks us to "return following int", yet Java method doStuff returns a String rather than an int.
zkvarz
Jan 31, 5:55 AMNo, method "static int doStuff(String text){ .....}" starts with int, therefore it must return an int. Btw, in square brakets "text" is a value that we put in this method in the main class.
thales
Jul 17, 7:34 AMmy solotion:
my code