0
嗨Java完全新手,這是我的第二個任務。我已經寫了使用數組列表彩票碼的方法,我有兩個問題:如何獲得ArrayList shuffle生成多個不完全相同的
- 相同的混洗表產生用於請求每一行。
- 這些行不打印。
public static void irishLottery() {
Scanner input = new Scanner(System.in);
double cost = 0;
System.out.println("How many lines of lottery up to 10 would you like?");
int linesam = input.nextInt();
ArrayList<Integer> numbers = new ArrayList<Integer>();
//define ArrayList to hold Integer objects
for (int lottonos = 0; lottonos < 45; lottonos++) {
numbers.add(lottonos + 1);
}
Collections.shuffle(numbers);
System.out.print("Your lottery numbers are: ");
for (int lncounter = 1; lncounter <= linesam; lncounter++) {
for (int j = 0; j < 6; j++) {
System.out.println(numbers.get(j) + " ");
}
}
}
2)也許'System.out.print',而不是'System.out.println' – boburShox
這是給你同樣的名單,因爲你洗牌一次,是印刷同樣的重複。每次打印時需要再次洗牌。 – Ric