yes or no?


Collapse 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

  • Admin 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.

  • We use Java 7 which does allow it. This challenge can use characters which could always be used.

  • This 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.

    cont...
  • Nevermind... Forgot that characters require single quotes.

  • my solution:

    my code

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