SHARE
TWEET

ye

God_Goku324 Apr 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Arrays Programming Assignment 1 Template
  2. public class ArraysProblem2
  3. {
  4.     public static void main()
  5.     {
  6.         //Declare an array for the 300 randomly generated numbers
  7.         int [] array = new int [300];
  8.  
  9.         //Declare an array for the 51 numbers to count occurences of
  10.         int [] array2 = new int [51];
  11.         //Fill the numbers array with random numbers 0-50 inclusive
  12.         for(int i = 0; i<array.length;i++)
  13.             array[i] = (int) (Math.random()*51);
  14.         for(int i = 0; i<array2.length;i++)
  15.             array2[i] = (int) (Math.random()*51);
  16.         //Print the numbers array 10 numbers per line separated by tabs
  17.         for(int i = 0; i <= 29; i++)
  18.         {
  19.             for(int j = 0; j <= 9; j++)
  20.             {
  21.                 System.out.print(array[i+j]+"\t");
  22.             }
  23.             System.out.print("\n");
  24.         }
  25.         System.out.println("--------------------------------------------");
  26.         //Loop through the numbers array incrementing
  27.         // indicis of the occurences array appropriately
  28.         int num = 0;
  29.         int count = 0;
  30.         for(int i = 0;i<array.length;i++)
  31.         {
  32.             count = 0;
  33.             num = array[i];
  34.             for(int j = 0; j<array.length;j++)
  35.             {
  36.                 if(num == array[j])
  37.                     count++;
  38.             }
  39.             System.out.println(num+":"+count);
  40.         }
  41.         //Loop through the occurences array printing the numbers
  42.         // and their occurences
  43.                 for(int i = 0;i<array2.length;i++)
  44.         {
  45.             count = 0;
  46.             num = array2[i];
  47.             for(int j = 0; j<array2.length;j++)
  48.             {
  49.                 if(num == array2[j])
  50.                     count++;
  51.             }
  52.             System.out.println(num+":"+count);
  53.         }
  54.  
  55.     }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top