Advertisement
Guest User

Untitled

a guest
May 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class BallsAndBins {
  5.  
  6. static int[] throwBalls(int m, int n){
  7. int arr[]=new int [m];
  8. Random rand = new Random(System.currentTimeMillis());
  9. for (int i=0; i<n; i++) {
  10. int a=rand.nextInt(m);
  11. arr[a]=arr[a]+1;
  12. }
  13. return arr;
  14. }
  15.  
  16.  
  17.  
  18.  
  19. public static void main(String[] args) {
  20.  
  21. @SuppressWarnings("resource")
  22. Scanner keyboard=new Scanner(System.in);
  23. System.out.println("Enter Array Size: ");
  24. int m=keyboard.nextInt();
  25. System.out.println("Enter Ball Count: ");
  26. int n=keyboard.nextInt();
  27.  
  28. int arr2[]=new int[m];
  29. arr2=throwBalls(m,n);
  30.  
  31. for (int i=0; i<m; i++) {
  32. System.out.println(arr2[i]);
  33. }
  34.  
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement