Advertisement
Guest User

Java dobbelsteen stats

a guest
Sep 23rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. class Main {
  5.   public static void main(String[] args) {
  6.     Scanner scanInput = new Scanner(System.in);
  7.     Random rng = new Random();
  8.  
  9.     System.out.println("Hoevaak moet er gerold worden?");
  10.     int numberOfDice = scanInput.nextInt();
  11.     int[] dices = {0,0,0,0,0,0};
  12.     int total = 0;
  13.     for (int i=0; i<numberOfDice;i++) {
  14.       int roll = rng.nextInt(6) + 1;
  15.       total += roll;
  16.       dices[roll - 1]++;
  17.     }
  18.     System.out.println("Een: " + dices[0]);
  19.     System.out.println("Twee: " + dices[1]);
  20.     System.out.println("Drie: " + dices[2]);
  21.     System.out.println("Vier: " + dices[3]);
  22.     System.out.println("Vijf: " + dices[4]);
  23.     System.out.println("Zes: " + dices[5]);
  24.     float average = (float)total / (float)numberOfDice;
  25.     System.out.println("Gemiddelde: " + average);
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement