Yes or No!

Optional Node
Collapse 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


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.


  • Top paragraph asks us to "return following int", yet Java method doStuff returns a String rather than an int.

  • No, 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.

  • my solotion:

    my code

Contact Us
Sign in or email us at [email protected]