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

  • SEARCH
  • Home
  • 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 7489135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:12:17+00:00 2026-05-29T15:12:17+00:00

I have tried various techniques to check the values of user input in this

  • 0

I have tried various techniques to check the values of user input in this method. The user should only be able to enter a ‘1’ or a ‘0’. If any other input is used there should be an error message and the program exits. Any ideas? I got it to work for the first digit but not the second through the tenth.

    System.out.println("Enter a ten digit binary number.  Press 'Enter' after each digit.  Only use one or zero. :");

        binary[0] = keyboard.nextInt();

        for (index = 1; index < 10; index++)
            binary[index] = keyboard.nextInt();// fill array with 10 binary
                                                // digits from user. User
                                                // must press 'Enter' after
                                                // each digit.
  • 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-05-29T15:12:18+00:00Added an answer on May 29, 2026 at 3:12 pm

    Try this:

        Scanner scanner = new Scanner(System.in);
        if (scanner.hasNext())
        {
            final String input = scanner.next();
            try
            {
                int num = Integer.parseInt(input, 2);
            }
            catch (NumberFormatException error)
            {
                System.out.println(input + " is not a binary number.");
                //OR You may exit here, if you don't want to continue
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched the documentation and tried various techniques but have't found a suitable
I have tried searching over the internet about this problem but not able to
I have tried the various techniques described to serialize a plist I need in
I have tried various solutions provided on this site and others to implement touch
I have tried various methods to try and get this working correctly (I am
I have tried various setups with input and my one second timer but nothing
Can i shorten this to one line? I have tried various ways but can't
I have tried various methods and this is the closest I have gotten, but
I have tried all of these various ways to set the value of the
I have various Debug.WriteLine messages, I tried to see those messages using export MONO_DEBUG_LEVEL=debug,

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.