Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Lab001 {
- public static void main(String[] args) {
- // Create a random number generator
- Random rn = new Random();
- int k = 0;
- // Create arrays X & Y
- int[] Xarr = new int[50];
- int[] Yarr = new int[50];
- // Create Arrays A & B
- int[] ArrA = new int[100];
- int[] ArrB = new int[100];
- // Create a loop that generates numbers to put inside of array X.
- for(int a = 0 ; a < Xarr.length ; a++){
- int xnum = rn.nextInt(20) + 1;
- Xarr[a] = xnum;
- //TEST CODE: X ARRAY
- //System.out.println(i + "\t" + Xarr[i]);
- }
- // Create a loop that generates numbers for array Y.
- for(int b = 0 ; b < Yarr.length ; b++){
- int ynum = rn.nextInt(20) + 1;
- Yarr[b] = ynum;
- //TEST CODE: Y ARRAY
- //System.out.println(j + "\t" + Yarr[j]);
- }
- for(int i = 0 ; i < Xarr.length ; i++){
- for(int j = 0 ; j < Yarr.length ; j++)
- //Compare. If the two are the same, they go inside of A.
- if (Xarr[i] == Yarr[j]){
- ArrA[k] = Xarr[i];
- k++;
- System.out.println(ArrA[k]);
- break;
- }
- /*
- // If the two numbers are different, they'll be placed inside of B.
- }else{
- ArrB[k] = Xarr[i1];
- k++;
- break;
- }*/
- }
- // Print array A & B
- System.out.println(ArrA);
- System.out.println(ArrB);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement