-2
我想獲得一些我正在編寫的程序的幫助。我想輸出兩個,他們的臉部頻率加在一起。這是我寫的最新代碼。現在非常基本,寫得很差。我對Java編碼非常陌生,所以請給我任何提示和技巧,以幫助我:)。如何輸出兩個骰子並將它們加在一起
import java.util.Random;
public class DiceRolling {
public final static Random randomNumbers = new Random();
public static void main(String[] args) {
int[] dice1 = new int[7];
int[] dice2 = new int[7];
// prints out the headings
for (int headOne = 1; headOne <= 6; headOne++)
System.out.print(" " + headOne);
System.out.println();
for (int headTwo = 1; headTwo <= 6; headTwo++)
System.out.println(headTwo);
// The rolls of the two dices begins here
for (int frequencyOne = 0; frequencyOne < 36000000; frequencyOne++) {
++dice1[1 + randomNumbers.nextInt(6)];
}
// output faces of die
for (int faceOne = 1; faceOne < dice1.length; faceOne++) {
System.out.print(" " + dice1[faceOne]);
}
}
}
什麼問題?有什麼不起作用嗎?爲什麼要導入'java.lang.reflect.Array'? – Thilo
'dice2'永遠不會被使用,那是故意的嗎?你應該問一個更具體的問題。 –