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 8554933
In Process

The Archive Base Latest Questions

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

So far I got this program to run but I got stock in this

  • 0

So far I got this program to run but I got stock in this part: the program should keep prompting the user for a new word until a word representing a valid binary number is input by the user. I know I’m suppose to use a loop but I dont know where to put it.

package programming_assignment_1;

import java.util.Scanner;

public class Programming_Assignment_1 {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        System.out.print("Please imput a binary number : ");
        String binary;
        binary = sc.next();
        boolean isBinary = true;

        char[] values = binary.toCharArray();
        for(int i=0; i<values.length; i++)
        {
                if( (values[i] != '0') && (values[i] != '1') )
                {
                isBinary = false;
                break;
                }
        }
        if(!isBinary)
        {
        System.out.println("this is not a binary number");
        }
        else
        {
            for(int i=0; i<1; i++)
            {
                 String consecutive1s = "111";
               if (binary.indexOf(consecutive1s) != -1)
            {
                System.out.println("accepted");
            }
            else
            {
              System.out.println("rejected");  
            }
            }
        }

    }
}
  • 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-11T14:59:57+00:00Added an answer on June 11, 2026 at 2:59 pm
    ...
    public static void main(String[] args) {
        // TODO code application logic here
        boolean accepted = false;
        while(!accepted) {
           Scanner sc = new Scanner(System.in);
           ...
    
           if(!isBinary) {
               System.out.println("this is not a binary number");
           } else {
               accepted = true;
               ...
    
           }
           ...
    
        } // while
    } // main
    

    Additionally, I am not sure about your “for” loop – it does not add anything to your program, since it is executed exactly once …

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

Sidebar

Related Questions

I post this previously in Adobe Forum but haven't got any answers so far.
I am creating a stock exchange type program and so far I've got the
I got this far: :~ curl -u username:password -d status=new_status http://twitter.com/statuses/update.xml Now, how can
I'm trying to implement a Haskell Bag (multiset). So far I've got this data
So this is as far as I got. Before I spend days throwing darts
Here is what I've got so far.. I'm using this as a keybind. I
This seems like it should be so simple, but i am having some serious
I am just starting with Sphinx. So far I got it installed successfully, got
I am trying to recreate the Notes application. So far I got the following:
Here is what i've got so far: /(netscape)|(navigator)\/(\d+)(\.(\d+))?/.test(UserAgentString.toLowerCase()) ? ' netscape'+RegExp.$3+RegExp.$4 : '' I'm

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.