Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:59:20+00:00 2026-06-12T14:59:20+00:00

I am trying to get a valid input of y, Y, n , or

  • 0

I am trying to get a valid input of “y”, “Y”, “n” , or “N”.

If the input is not valid (for example any word that starts with a “y” or “n”) I want it to re-prompt the user for input.

So far I have:

while  (again.charAt(0) != 'N' && again.charAt(0) != 'n' && again.charAt(0) !='Y' && again.charAt(0) != 'y' ) {
    System.out.println ("Invalid Inpur! Enter Y/N");
    again = numscan.next();
}

if (again.charAt(0)== 'N' || again.charAt(0) == 'n') {
    active = false;                   
} else {
    if (again.charAt(0)== 'Y' || again.charAt(0) == 'y'){
        active = true;
        random = (int) (Math.random () *(11));
    }
}

The problem I am having is if I enter any word that starts with the letter “y” or “n” it senses it as valid input (since it is the character at slot 0). I need help fixing this so I can re-prompt the user when they enter a word that starts with a “y” or “n”.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:59:21+00:00Added an answer on June 12, 2026 at 2:59 pm

    Assuming again is a string containing the complete user input, you could use:

    while (!again.equals("N") && !again.equals("n") ...
    

    The .equals() method will match only if the entire string matches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to get user input from a Javascript prompt into a PHP
I am trying to have a loop continue to prompt the user for an
i`m trying to get a string handler which takes input from user in a
I'm trying to get a number as CLI input from python. Valid input should
Trying to get a wildcard search to pick up on any text in org_name
I have an extremely simple example trying to use Data Annotations with unobtrusive javascript
I'm trying to catch an input error - where the only valid input is
I’m trying to make a html5 form that contains one email input, one check
I'm trying to do something common enough: Parse user input in a shell script.
I am trying to get the return from the mail.php but it does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.