我的代码有问题,这是一个简单的骰子游戏:
import java.util.Random;
class Zaruri {
public static void main(String args[]) {
Random roll = new Random();
int[] zar = new int[2];
for (int i = 0; i < 1; i++) {
for(int k = 0; k < 2; k++){
zar[i] = (int) (roll* 6) + 1;
}
if (zar[0] == zar[1]) {
System.out.println("Your numbers are : " + zar[0] + " and " + zar[1] + "\nYou won! \nYEEEY!!");
} else {
System.out.println("Your numbers are : " + zar[0] + " and " + zar[1] + "\nYou lost, better luck next time!");
}
}
}
}
我不知道如何使它工作,首先它不会让打印出第二个骰子(它总是 0),如果我放了更多然后 1 卷和 (roll.nextDouble * 6) + 1; 它会起作用,但我不想超过 1 卷。你能帮助我吗 ?我究竟做错了什么??