Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[] resultDice = {0, 0, 0, 0, 0, 0, 0};
- public static int numberOfUserRolls = 0;
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Please enter the number of rolls. But don't forget, if you enter a number smaller than 20, you will receive an error!");
- numberOfUserRolls = scanner.nextInt();
- rollDice();
- }
- public static void rollDice() {
- int dice = 0;
- for (int i = 0; i < numberOfUserRolls; i++) {
- Random rnd = new Random();
- dice = 1 + rnd.nextInt((6 - 1) + 1);
- resultDice[dice] = resultDice[dice] + 1;
- }
- showResults();
- }
- public static void showResults() {
- System.out.println("You rolled " + numberOfUserRolls + " times the dice.");
- System.out.println("You rolled one " + );
- System.out.println("You rolled two " + );
- System.out.println("You rolled three " + );
- System.out.println("You rolled four " + );
- System.out.println("You rolled five " + );
- System.out.println("You rolled six " + );
- System.out.println("");
- System.out.println("The percentage of 1 is " + + "%" );
- System.out.println("The percentage of 2 is " + + "%" );
- System.out.println("The percentage of 3 is " + + "%" );
- System.out.println("The percentage of 4 is " + + "%" );
- System.out.println("The percentage of 5 is " + + "%" );
- System.out.println("The percentage of 6 is " + + "%" );
- }
- }
Add Comment
Please, Sign In to add comment