我正在尝试制作一个"滚动两个骰子"的程序,并将数量和需求结合起来,直到特定数量达到7或11,但每次运行它都会一直持续下去.
double total = 0;
while (total != 7 || total != 11) {
DecimalFormat x = new DecimalFormat("#");
double dice1 = Math.random() * 6 + 1;
double dice2 = Math.random() * 6 + 1;
double total = (dice1 + dice2);
System.out.println("Dice 1: " + x.format(dice1) + " Dice 2: " + x.format(dice2) + " Total: " + x.format(total));
}
Run Code Online (Sandbox Code Playgroud)
我认为它是因为int total设置为0并且没有从循环中得到总数但是我该如何解决这个问题呢?