Java rolling dice + csv array output I have made a program to take x number of die and rolls them y number of times, then stores the data into an array so that I may output a CSV file. Everything works as intended, but I am having trouble figuring out how to increase the number of die to anything substantial. Right now I am using a switch, but linearly adding code like this seems inefficient, not to mention it will crash with amounts larger than 4 die. Is there some shortcut for adding variable number of switch statements? Any other methods would work as well, I am just not clever enough to come up with any as of yet.

import javax.swing.JOptionPane;

public class histogram {
public static void main(String[] M83cluster) {

    // # of die
    String N = JOptionPane.showInputDialog("How many dice would you like to roll?");
    int numofDie = Integer.parseInt(N);
    // # of rolls
    String M = JOptionPane.showInputDialog("how many times would you like to roll?");
    int numofRolls = Integer.parseInt(M);
    int maxValue = numofDie*6;
    int[] taco = new int[maxValue]; // for every die there will be at most 6 values.

    // rolls the die and obtains a value.
    for (int i=0;i&lt;numofRolls; i++) {
        int oneTotalRoll = 0;
        for (int k=0;k&lt;numofDie; k++) {
             oneTotalRoll += (int)(1+6*Math.random());
        }

        //int oneTotalRoll = (int) (valueofDice * numofDie);                
        System.out.println("ROLL: " + oneTotalRoll);            

        // for each roll, increment taco[] array.
        switch (oneTotalRoll) {
            case 4: taco[0] += 1;
                break;
            case 5: taco[1] += 1;
                break;
            case 6: taco[2] += 1;
                break;
            case 7: taco[3] += 1;
                break;
            case 8: taco[4] += 1;
                break;
            case 9: taco[5] += 1;
                break;
            case 10: taco[6] += 1;
                break;
            case 11: taco[7] += 1;
                break;
            case 12: taco[8] += 1;
                break;
            case 13: taco[9] += 1;
                break;
            case 14: taco[10] += 1;
                break;
            case 15: taco[11] += 1;
                break;
            case 16: taco[12] += 1;
                break;
            case 17: taco[13] += 1;
                break;
            case 18: taco[14] += 1;
                break;
            case 19: taco[15] += 1;
                break; 
            case 20: taco[16] += 1;
                break;
            case 21: taco[17] += 1;
                break;
            case 22: taco[18] += 1;
                break;
            case 23: taco[19] += 1;
                break;
            case 24: taco[20] += 1;
                break;
            case 25: taco[21] += 1;
                break;
        }
    }
    System.out.println("-------");

    String gorgon = null;  // prints outcome
    for (int g=0; g&lt;maxValue ; g++) {
        String gigabolt = (taco[g] + ",");
        gorgon += gigabolt;
        // System.out.print(gigabolt);
    }
    if (gorgon.endsWith(",")) 
        gorgon = gorgon.substring(4, gorgon.length() - 1);
    System.out.print(gorgon);
}
}
Indentation

Your code's indentation is wrong, the class and method declaration should not be on the same line.



Whitespace

Your code has incorrect whitespace in places, for example:


int maxValue = numofDie*6;



and here:


case 4: taco[0] += 1;
    break;



The first one is missing whitespace between the operators, and the second one should have the taco[0] statement on a new line.



switch:

Your entire switch statement could be condensed to this:

taco[oneTotalRoll - 4] += 1;


All of your cases were testing if oneTotalRoll's value was 4 more than the array position, so in that case, you could just minus four from oneTotalRoll and use that as an index position.



Naming

You have variables named like taco , gorgon, N and M.

These should be named to things that are closer to their usage and what they are, for example:


taco into rollCount
gorgon into condensedList
N into stringDieCount
M into stringRollCount




String concatenation

Instead of string concatenating everything at the end, consider using an Array join to "glue" everything together with a common join (,).