Advertisement
Yuvalxp8

Page-92 Ex-35

May 3rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. import java.util.*;
  2. public class Targil35
  3. {
  4.  
  5.     static Scanner in = new Scanner (System.in);
  6.     public static void main(String[] args)
  7.     {
  8.         int A;
  9.         int B;
  10.         int Z = 100;
  11.         int c = 0;
  12.         int count = 0;
  13.         A = (int)(Math.random() * Z );
  14.         B = (int)(Math.random() * Z );
  15.         int[] a = new int[A];
  16.         int[] b = new int[B];
  17.         int[] z = new int[Z];
  18.        
  19.         for(int i = 0 ; i < Z ; i ++)
  20.             z[i] = 0 ;
  21.        
  22.         System.out.println("Length of Array a: " + A);
  23.         System.out.println("Length of Array b: " + B);
  24.        
  25.         for(int i = 0 ; i < A ; i ++)
  26.         {
  27.             a[i] = (int) (Math.random() * Z);
  28.             System.out.println("Output: " + a[i]);
  29.             System.out.println();
  30.         }
  31.         System.out.println();
  32.         System.out.println();
  33.        
  34.         for(int i = 0 ; i < B ; i ++)
  35.         {
  36.             b[i] = (int) (Math.random() * Z);
  37.             System.out.println("Output: " + b[i]);
  38.             System.out.println();
  39.         }
  40.        
  41.         for(int i = 0 ; i < A ; i ++)
  42.         {
  43.             for(int j = 0 ; j < B ; j ++)
  44.             {
  45.                 if(a[i] == b[j])
  46.                 {
  47.                     z[a[i]] ++ ;
  48.                 }
  49.             }
  50.         }
  51.        
  52.         for(int i = 0 ; i < Z ; i ++)
  53.         {
  54.             if(b[i] != 0)
  55.             {
  56.                 c ++;
  57.             }
  58.         }
  59.        
  60.         System.out.println();
  61.        
  62.         for(int i = 0 ; i < Z ; i++)
  63.         {
  64.             System.out.println(b[i] + " ");
  65.         }
  66.        
  67.         System.out.println();
  68.         System.out.println();
  69.         System.out.println("c = " + c);
  70.        
  71.         int[] f = new int[c];
  72.         for(int i = 0 ; i < Z ; i ++)
  73.         {
  74.             if(b[i] != 0)
  75.             {
  76.                 f[count] = i;
  77.                 count ++;
  78.             }
  79.         }
  80.        
  81.         System.out.println();
  82.        
  83.         for (int i = 0 ; i < c ; i ++)
  84.             System.out.println(f[i] + " ");
  85.     }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement