0

I am fairly new to coding, with around 4 months of experience and self taught. I've used arrays and understand how you write them. But for this specific instance, I am looking to make the values in an array of 15 ints set between the number 1 and 15, without any duplicate values.

If I could be pointed in the right direction I would greatly appreciate it.

Thanks for reading!

Ebp90
  • 15
  • 2
  • Please search Stack Overflow before posting. There are many questions already there which can handle your problem. – Tim Biegeleisen Aug 05 '18 at 15:42
  • public static void main(String[] args) { Set integers = new LinkedHashSet<>(); Random r = new Random(); while (true) { integers.add((r.nextInt(16 - 1) + 1)); if (integers.size() == 15) break; } int arr[] = new int[integers.size()]; int i = 0; for (int num : integers) { arr[i++] = num; } //arr now contains 15 random numbers with no duplicates, do whatever you need with it. } – Mohamed Yehia Aug 05 '18 at 15:57

0 Answers0