mercredi 19 avril 2017

Checking for duplicate numbers in a random array

I have an array that is filled with random numbers. I want to check if there are any duplicate numbers in the array but I am having problems. This is what I have so far.

        Random randomNum=new Random();        
       int[] array = new int[100];
    for(int i = 0; i <  array.length; i++) {
        array[i] = randomNum.nextInt(100); //0-99
        System.out.print(array[i] + "  ");}

    for(int index = 0; index < array.length; index++)
      {
       if(array[index] == array[index+1])
        System.out.println("Match in"+array[index]);
  }

Aucun commentaire:

Enregistrer un commentaire