Hi all, I'm new to java and here is my code. It runs, but the output is not what I wanted. This project allows the user to enter up to 6 lottery tickets and I have to generate random numbers 0-49. The number generate fine, but the number of tickets entered doesn't. If i enter two tickets, It'll still print out six. It should print out the number of tickets based on user input. Please help. Thank you. My teacher does not allow us to use arrays for this project. For extra credit we can use 2d arrays, but no arraylists. How would I rewrite this code just using 2d arrays?
import java.util.Collections;
import java.util.ArrayList;
import java.util.Scanner;
public class LotteryTest {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
{
ArrayList<Integer> numbers = new ArrayList<Integer>();
System.out.println("Please enter the number of tickets you want");
int numtix = input.nextInt();
for(int i = 0; i <= 49; i++){ //loop to choose
numbers.add(i+0);
}
for (int i=0; i<6; i++) { //loop for # of lottery tickets
Collections.shuffle(numbers); //randomly shuffle elements of arraylist
System.out.print("\nLotto Ticket #"+(numtix)+": ");
for (int j=0; j<6; j++) { // determine how many numbers for each ticket
System.out.print(numbers.get(j) + " ");
}
}
}
}
}