Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to print out the number of times two six sided dice add to 4
    primarykey
    data
    text
    <p>My previous question was similar to this, except I did not mention my ending goal,</p> <p>In this code I have one die, and I print out the number of times it rolls a 4. Now I want to know if I have two dice, both six sided, how many times both would roll 2 and thus add to 4. </p> <p>However, I would need to use arrays because it is mandatory in this assignment. I have tried adding another exception in the <code>if</code> statement, except I keep realizing that I need to be actually using arrays in the program. 1000 arrays should be stored, since the dice has to roll 1000 times, and thus check how many times it added to 4 from the rolls, then print the amount of times.</p> <pre><code>import java.io.*; public class dont { public static void main(String[] args) throws Exception { // System.out.println(input()); int[] counts = new int[13]; System.out.print("The number of times it rolls 4 on two 6 sided dice :" + counts); } public static int input () throws IOException { BufferedReader myInput = new BufferedReader (new InputStreamReader System.out.println("Hello and welcome to the program"); System.out.println("In this program two six sided dices will be rolled and one eleven sided dice will be rolled (1000 times each"); int sum; int[] counts = new int[13]; System.out.println("The dices will be rolled to determine the odds of how many times the roll 2 comes up on both dies(Press any key to con't) "); myInput.readLine(); //int count2=0; int Sixside; for (int i = 0; i &lt; 1000; i++) { // two dice that add to 4, after being rolled one thousand times Sixside = (int)(Math.random ()*6+1)+(int)(Math.random ()*6+1) == 4; //print the number of times they add to 4 counts[sum]++; } counts[i] = Sixside; { //return array to main return counts [13]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload