Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import java.util.*;
  2. public class DiceRoll2
  3. {
  4. static Scanner scan= new Scanner(System.in);
  5. public static void main(String[]args)
  6. {
  7. int times=0;
  8. System.out.println("How many sides: ");
  9. int sides=scan.nextInt();
  10. System.out.println("How many rolls: ");
  11. int rolls=scan.nextInt();
  12. int[] outcomes = new int[rolls];
  13.  
  14. for(int i=0;i<rolls;i++)
  15. {
  16. int a=((int)(Math.random()*sides)+1);
  17. outcomes[i]=a;
  18. System.out.println((i+1)+"-"+outcomes[i]);
  19. }
  20. int max=outcomes[0];
  21. for(int i=0;i<rolls;i++)
  22. {
  23. if(outcomes[i]>=max)
  24. max=outcomes[i];
  25. }
  26. for(int i=0;i<rolls;i++)
  27. {
  28. if(outcomes[i]==max)
  29. times+=1;
  30. }
  31. System.out.println("\nThe highest rolled was "+max+" and it rolled "+times+" time(s).");
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement