Originally Answered: Help with a java program?
So we'll make an array, of length 18, and thus with indices 0-17. Each index will represent the number of rolls possible for making that number, only we'll adjust the index up by 1 so we go from 1-18 instead of 0-17. For example, index 0 will store the amount of ways you can roll 1, index 1 will store the amount of ways you can make 2, all the way up until index 17 stores the amount of ways you can roll 18.
We'll start off by declaring our integer array and setting it to size 18:
introlls = new int;
By default it is filled with all 0's, which is fine to start. We now have to fill it with the proper values. Basically what we'll do is loop through all possible combinations of rolls, and add their sums. We'll do this with a series of 3 nested for loops - the outermost will be the roll of the first dice, the middle the second dice, and the innermost the third dice. This way, the inner loop will run once for each value of the middle loop, which will in turn run once for each value of the outer loop. So for every possible value of the first dice, we'll find every possible value for the second dice, and for every possible value of the first two dices, we'll find ever possible value of the third dice.
It will work something like this:
111, 112, 113, 114, 115, 116, 121, 122, 123, 124, 125, 126, 131, 132, 133, 134, 135, 136, 141, 142, 143, 144, 145, 146, 151, 152, 153, 154, 155, 156, 161, 162, 163, 164, 165, 166, 211... and so on.
The code to do this is as follows:
for (int a = 1; a <= 6; a++)
for (int b = 1; b <= 6; b++)
for (int c = 1; c <= 6; c++)
int value = a+b+c;
So for each possible roll we compute the value by adding the three dies and then go to that position in the array and increase the number of possible ways to make this value by 1. At the end we just need to print all these values:
for (int x = 0; x < rolls.length; x++)
System.out.println((x+1) + " " + rolls[x]);