Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public static int[] resultDice = {0, 0, 0, 0, 0, 0, 0};
  2. public static int numberOfUserRolls = 0;
  3.  
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. 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!");
  7. numberOfUserRolls = scanner.nextInt();
  8.  
  9. rollDice();
  10.  
  11. }
  12.  
  13. public static void rollDice() {
  14. int dice = 0;
  15.  
  16. for (int i = 0; i < numberOfUserRolls; i++) {
  17.  
  18. Random rnd = new Random();
  19.  
  20. dice = 1 + rnd.nextInt((6 - 1) + 1);
  21. resultDice[dice] = resultDice[dice] + 1;
  22. }
  23.  
  24. showResults();
  25.  
  26. }
  27.  
  28. public static void showResults() {
  29. System.out.println("You rolled " + numberOfUserRolls + " times the dice.");
  30.  
  31. System.out.println("You rolled one " + );
  32. System.out.println("You rolled two " + );
  33. System.out.println("You rolled three " + );
  34. System.out.println("You rolled four " + );
  35. System.out.println("You rolled five " + );
  36. System.out.println("You rolled six " + );
  37.  
  38. System.out.println("");
  39. System.out.println("The percentage of 1 is " + + "%" );
  40. System.out.println("The percentage of 2 is " + + "%" );
  41. System.out.println("The percentage of 3 is " + + "%" );
  42. System.out.println("The percentage of 4 is " + + "%" );
  43. System.out.println("The percentage of 5 is " + + "%" );
  44. System.out.println("The percentage of 6 is " + + "%" );
  45.  
  46. }
  47. }
Add Comment
Please, Sign In to add comment