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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:51:38+00:00 2026-05-26T03:51:38+00:00

I am having som slight difficulties with the following problem. I have initialized a

  • 0

I am having som slight difficulties with the following problem.

I have initialized a boolean array called numberArray with 31 indexes. The user is supposed to enter 5 digits between 1 and 30, and each time a digit is entered, the program is supposed to set the proper index to true. For instance, if I enter 5 then:

numberArray[5] = true;

However, if the user enters the value 5 a second time, a message should be given to the user that this number has already been entered, and so the user has to choose a different value. I have tried to create a loop as follows:

public void enterArrayValues() {
    for(int i = 1; i < 6; i++) {
        System.out.print("Give " + i + ". number: ");
        int enteredNumber = input.nextInt();
        while (numberArray[enteredNumber] = true) {
            System.out.println("This number has already been chosen.");
            System.out.print("Give " + i + ". number again: ");
            enteredNumber = input.nextInt();
        }
        numberArray[enteredNumber] = true;
    }
}

The problem is that when I run the program, I automatically get the message “The number has already been chosen” no matter what I enter. Even the first time I enter a number. I don’t get this. Isn’t all the values in the boolean array false by default?

I would greatly appreciate it if someone could help me with this!

  • 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-26T03:51:38+00:00Added an answer on May 26, 2026 at 3:51 am
    while (numberArray[enteredNumber] = true) {
    

    make that

    while (numberArray[enteredNumber] == true) {
    

    or change to

    while (true == numberArray[enteredNumber]) {
    

    or simply drop the ==true

    while (numberArray[enteredNumber]) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a problem with Scala import. I have an import problem with two classes.
Having the following code, how can I have get receive a map, and return
Having a really strange problem. Scenario: PHP5.2.9, IIS7, PHP running as FastCGI. I have
Having a problem getting a TreeView control to display node images. The code below
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
having a file with the following for example: DEFINE('INTERESTS_1','a'); DEFINE('INTERESTS_2','d'); DEFINE('INTERESTS_3','g'); DEFINE('INTERESTS_4','c'); Is it
Having the following code: int main(int argc, char* argv[]) { // program code std::cout
Having a very odd problem. After processing of a file I read a txt
Having the following code: template<typename T, typename OutStream = std::ostream> struct print { OutStream

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.