everybody!
I have an assignment that is to create a small program to generate different bets for the lottery. I've got hours wondering about the piece of code that should create the array with distinct numbers within each bet. The problem is that, although I've tried to cut repetitions off, my code keeps generating bets with repeating numbers within each line of the matrix. What do you think I should look more deeply?
public static void main(String[] args) {
//Ask the user how many lines of 15 numbers will be created
System.out.print("How many lines should the matrix have? ");
Scanner input = new Scanner(System.in);
int numberOfLines = input.nextInt();
// Create the two-dimension array.
int[][] numbers = new int[15][numberOfLines];
for (int i = 0; i < numberOfLines; i++) {
for (int j = 0; j < 15; j++) {
boolean exist = false;
do {
numbers[j][i] = 1 + (int)(Math.random()*25);
for (int k = 0; k < j; k++) {
if (numbers[j][i] == numbers[k][i])
exist = true;
else {
exist = false;
}
}
} while (exist);
}
}
//Sort the array
int temp = 0;
for (int i = 0; i < numberOfLines; i++){
for (int j = 0; j < 15; j++) {
for (int k = (j + 1); k < 15; k++)
if (numbers[k][i] > numbers[j][i]) {
temp = numbers[j][i];
numbers[j][i] = numbers[k][i];
numbers[k][i] = temp;
}
}
}
//Print the array
System.out.println();
for(int i = 0; i < numberOfLines; i++) {
System.out.printf("Line %d: ", (i+1));
for (int j = 0; j < 15; j++){
System.out.printf("%4d",numbers[j][i]);
}
System.out.println();
System.out.println();
}
//System.out.println(numbers[0][1]);
//System.out.println(numbers[1][0]);
}
}