Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im having touble with the last couple of numbers. I want them to add up to 4 mil

ID: 3539565 • Letter: I

Question

Im having touble with the last couple of numbers. I want them to add up to 4 million. It either goes over or under 4 million when totaled. I have posted the paste bin link below.


for (int j = 0; j < times; j++)
    {
        temp = rand.nextInt(6);
        freqDie1[temp]++;
        freqDie2[temp]++;
        freqDie3[temp]++;
        freqDie4[temp]++;
    }
    for (int j = 0; j < 1; j++){
       
   
   
    System.out.println("Die one wins: " + freqDie1[j]);
    System.out.println("Die two wins: " + freqDie2[j]);
    System.out.println("Die three wins: " + freqDie3[j]);
    System.out.println("Die four wins: " + freqDie4[j]);
    }






<script src="http://pastebin.com/embed_js.php?i=Si3gjR3R"></script>

Explanation / Answer

Please add the check whether each values is less than a million or not as below and if exceeds break the loop

        for (int j = 0; j < times; j++)
        {
                temp = rand.nextInt(6);
                freqDie1[temp]++;
                freqDie2[temp]++;
                freqDie3[temp]++;
                freqDie4[temp]++;
                if(freqDie1[temp] > 1000000 || freqDie2[temp] > 1000000 || freqDie3[temp] >1000000 || freqDie4[temp] > 1000000)
                    break;
               
             
        }


OR




temp = 0;
        for (int j = 0; j < times; j++)
        {
            if(freqDie1[temp] > 1000000 || freqDie2[temp] > 1000000 || freqDie3[temp] > 1000000 || freqDie4[temp] > 1000000)
                  break;
           
                temp = rand.nextInt(6);
             
                freqDie1[temp]++;
                freqDie2[temp]++;
                freqDie3[temp]++;
                freqDie4[temp]++;
             
               
             
        }