小编Taj*_*lic的帖子

使Math.Random循环直到达到特定数字

我正在尝试制作一个"滚动两个骰子"的程序,并将数量和需求结合起来,直到特定数量达到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并且没有从循环中得到总数但是我该如何解决这个问题呢?

java random math dice

2
推荐指数
1
解决办法
962
查看次数

标签 统计

dice ×1

java ×1

math ×1

random ×1