This code randomly generates 4 lottery tickets and prints them on seperate lines. The code works, but what if I wanted this to print for 100 lottery tickets? Is there a way to write this with less lines of codes? Would using a for loop work?
import java.util.Collections;
import java.util.ArrayList;
public class Lottery5 {
public static void main(String[] args) {
//define ArrayList to hold Integer objects
ArrayList<Integer> numbers = new ArrayList<Integer>();
for(int i = 0; i <= 9; i++)
{
numbers.add(i+0);
}
Collections.shuffle(numbers);
System.out.print("Lotto Ticket #1: ");
for(int j =0; j < 10; j++)
{
System.out.print(numbers.get(j) + " ");
}
Collections.shuffle(numbers);
System.out.print("\nLotto Ticket #2: ");
for(int j =0; j < 10; j++)
{
System.out.print(numbers.get(j) + " ");
}
Collections.shuffle(numbers);
System.out.print("\nLotto Ticket #3: ");
for(int j =0; j < 10; j++)
{
System.out.print(numbers.get(j) + " ");
}
Collections.shuffle(numbers);
System.out.print("\nLotto Ticket #4: ");
for(int j =0; j < 10; j++)
{
System.out.print(numbers.get(j) + " ");
}
}
}