0

I made Lotto Programm in java. However, number is repeated. Program must be not duplicated. I do not know my wrong thing in this code.

import java.util.Random;

public class Lotto
{
  public static void main( String[] args )
  {
    Random randomNumbers = new Random();
    int[] array;

    array = new int[ 7 ];

    for(int num = 0; num < 6; num++){
      array[num] = 1 + randomNumbers.nextInt(45);

      for(int i = 1; i < num; i++)  
      {
        if( array[i] == array[num]){
           array[num] = randomNumbers.nextInt(45)+1;
           num = num - 1;
           break;
        }
      }
    }
    for(int num = 0; num < 6; num++){
      System.out.printf("%d ",array[num]);
    }
    System.out.println();
  }
}
이현정
  • 29
  • 4
  • When you check for duplicates, you don't consider array index `0`. – Thilo Jun 11 '15 at 06:54
  • 1
    With that fixed, I think the code should work. Did you get any duplicates that did not involve position `0`? – Thilo Jun 11 '15 at 06:56

0 Answers0