例如:如果该数字已在所有骰子掷骰中掷出 25%,则声明 (System.out.println("The dice might be loaded!")
import javax.swing.*;
class Dice
{
public static void main (String [] args)
{
int c = Integer.parseInt(JOptionPane.showInputDialog("How many sides?"));
int[ ] sides = new int[c];
String[ ] number = new String[c];
int max = c;
int min = 1;
int d = Integer.parseInt(JOptionPane.showInputDialog("How many times do you want to roll your dice?"));
for(int i=0;i<c;i++)
{
number[i] = (JOptionPane.showInputDialog("Enter side number:"));
}
for(int i=0;i<d;i++)
{
int r;
r = (int) Math.floor(Math.random() * max) + min; System.out.println(r);
sides[r-1] = sides[r-1] + 1;
}
for(int i=0;i<c;i++)
{
System.out.println(number[i] + " was rolled " + sides[i] + " times.");
}
}
}