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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:05:05+00:00 2026-06-10T00:05:05+00:00

I am attempting to learn Java Programming on my own (without classes/teachers/tutors/etc.) so this

  • 0

I am attempting to learn Java Programming on my own (without classes/teachers/tutors/etc.) so this is not a homework assignment.

My question has been alluded to in Java Challenge for beginners: Generate random numbers in a while loop, however, I have not advanced far enough into this book to have covered ArrayLists, as stated by the prior programmer who asked this question.

Answering this question definitely would help most beginner programmers better understand how to write statements for while loops, an often intricate process, especially for beginners.

The question is: Write a while loop that generates random numbers between 1 and 100 and stops looping after it generates the same number twice.

As you will recognize, running this program only creates an output of two random numbers between 1 and 100, each time it is run. I believe this error is encountered due to line 17: equal = numberCheck == values[i]; being incorrect since this is the statement defining when the while loops condition becomes true and therefore stops evaluating.

Any help is greatly appreciated. Thank you.

My code is:

import java.util.Random;

public class SameNumber {

    public static void main(String args[]) {

        Random rand = new Random();
        int[] values = new int[100];
        int counter = 0;
        boolean equal = false;

        for (int i = 0; i < 2; i++) {
            values[i] = rand.nextInt(100) + 1;
            System.out.println(values[i]);
            int numberCheck;
        }

        while (!equal) {
            for(int i = counter - 1; i >= 0; i--) {
                int numberCheck = values[i];
                equal = numberCheck == values[i];
             //}
                if (!equal) {
                    System.out.println(rand.nextInt(100) + 1);
                }

                for (int j = counter - 1; j >= 0; j--) {
                    if (numberCheck  == values[j]) {
                        break;
                    }
                }
            }
        }
    }
}

P.S.: I understand that this may sound ridiculous, however I have been working on this problem for about a week and trying to gather additional research, and I still could not arrive at the proper solution. I have been hesitant to ask for help since I am concerned that other programmers would answer with methods that I have not yet learned.

  • 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-10T00:05:06+00:00Added an answer on June 10, 2026 at 12:05 am

    I would set values to be an array of boolean values, and set it to true if your number is there. Then you would just use your random number as the index to that array:

    boolean[] values = new boolean[100];
    
    int index = Random.nextInt(100);
    while(!values[index]){
        System.out.println(index+1);
        values[index] = true;
        index = Random.nextInt(100);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: This may be a terribly simple question but I'm attempting to learn Python.
I am attempting to learn J and the book I am using says this
I've been attempting to learn programming (in C#) for a few years now. The
I am attempting to learn Java ee in my spare time. I wan't to
I'm following this tutorial attempting to learn XNA, but I'm having issues making my
Hey all I am attempting to learn MVC 2 and ASP etc through the
I'm attempting to learn myself up on F#, and I fear I'm not understanding
I am attempting to learn Ruby by converting a Java program to Ruby, but
I'm attempting to learn Scala coming from a Java background. Should the below program
I'm attempting to learn Haskell by writing a SIP client. The question I have

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.