将Dice one和Dice两个具有相同值并将其添加到整数时的问题

时间:2016-08-24 19:40:10

标签: java arrays for-loop

我目前正试图获得两个骰子具有相同值的次数。这是我到目前为止所做的。

public static void main(String [] args)
{
    System.out.print("Enter the amount of rolls you want to do: ");
    Scanner scan = new Scanner(System.in); 
    int r = scan.nextInt();
    final int FACES = 6, ROLLS = r;
    int [] rollCount = new int [FACES];
    int [] rolCount = new int [FACES];
    Die d1 = new Die();
    Die d2 = new Die();
    int myRoll = 0;
    int myRollTwo = 0;
    int Ident = 0;
    int i = 0;

    while (i <= 1)
    {
        int ii = 0;
        int iii = 0;
        for (ii = 1; ii <= ROLLS; ii++)
        {
            myRoll = d1.roll();
            rollCount[myRoll - 1]++;
        }

        for (ii = 1; ii <= ROLLS; ii++)
        {
            myRollTwo = d2.roll();
            rolCount[myRollTwo - 1]++;
            iii++;
        }
        if (myRoll == myRollTwo)
            {
                Ident++;
            }

        if (iii == ROLLS)
        {
            i++;
        }
    }


    System.out.println("Die Number\tDie One\tDie Two\tTotal\t Amount of Identical Rolls");
    for (i = 0; i < rollCount.length; i++)
    {
        System.out.println((i + 1) + "\t\t\t" + rollCount[i] + "\t\t" + rolCount[i] + "\t\t" + ((rollCount[i] + rolCount[i])*(i + 1)) + "\t\t" + Ident);
    }
}

我知道while循环结束时的if语句不起作用,因为它只会执行一次,所以我究竟要怎样才能获得两个骰子相同的次数?

0 个答案:

没有答案