Java code random number between 1 and 100 without repeating

Java code that will generate a random number between 1 and 100 without repeating the random numbers.

It’s for my exercise at school

@RodgersKhosa Replit ask is not for getting answers for your school projects. If you need help, members can help you but include that this is a school project when making the post


He said it was for school in his post…?

Yes they did. Even if they did not this is the kind of question that would be asked in school

1 Like

so I’m guessing that’s why my answer was removed

Yes that was why it was removed

1 Like

Hello @RodgersKhosa welcome to the community!

Like it was said before, we are not to give you direct answers but to help you with your growth!

That being said, we can give you a few tips!

  1. To use the random for your exercise you will need to import the random class from java.util to generate random numbers and the ArrayList class to store the unique numbers!
  2. After that you create an ArrayList that we will use to store the generated numbers.
  3. To generate the numbers you will need to create a loop. In the case of your exercise that loop needs to run 100 times.
  4. You will also need to check if the number is already in the ArrayList (this can be done using the contains method). (Remember that we need unique numbers, so we must check if the generated number is already in the list. If the number is already in the list, it’s not unique, so we shouldn’t add it to the list.)
  5. If the generated number is not in the list, it’s a unique number and we should add it to the list. We use the add method of the ArrayList class to add elements to the list.

This will give you a starting point to produce your code. Don’t forget that you need to print the numbers!

1 Like

When did that get there?

Okay, what class in java allows you to create an “array” of varibles with no repeating values.