I have an assignment where I have to have seven different lottery numbers ranging from 1 to 35. A separate powerball number should also be generated. The powerball number should be within the range of 1-10. I have to write a java program that gives eight sets of seven numbers plus one powerball number. It has to have an array and the random() method has to be used and at least one repetition statement. I got it to give me one set of seven and a powerball number. I tried to do a "while...do" statement but it created an infinite loop until I stopped the process. A very, very fast infinite loop. Here's what I have I just need to figure out what I need to do in order to loop and create a set of 8. I tried the "For" loop statement but I wasn't sure where in the code it needed to go. Maybe it has to be rewritten completely, I don't know. I'm new to java and I'm doing the best I can. Here's what I have, I'm at a loss:
import java.util.Collections;
import java.util.ArrayList;
public class Lottery //Declare the class
{
public static void main(String[] args)
{
//To display set of seven numbers between 1 - 35
ArrayList<Integer> numbers = new ArrayList<Integer>();
for (int i = 0; i < 35; i++)
{
numbers.add(i + 1);
}
Collections.shuffle(numbers);
System.out.print("This week's numbers are: "); //This displays the first 7 set of random numbers
for (int j = 0; j < 7; j++)
{
System.out.print(numbers.get(j) + " ");
}
//To display a powerball number between 1 - 10
ArrayList<Integer> pNum = new ArrayList<Integer>();
for (int p = 0; p < 10; p++)
{
pNum.add(p + 1);
}
Collections.shuffle(pNum);
System.out.print("The powerball number is: "); //This displays the random powerball number
for (int q = 0; q < 1; q++)
{
System.out.print(pNum.get(q) + " ");
}
}
}