Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package java1920;
- import java.util.Scanner;
- import java.util.Arrays;
- import java.lang.Math;
- public class Lesson_0_Activity_0 {
- public static void main(String[]arg) {
- Scanner kb = new Scanner (System.in);
- System.out.println("Enter an array length (must be 10 or greater): ");
- int arrLength = kb.nextInt();
- if (arrLength < 10) {
- while (arrLength < 10) {
- System.out.println("Enter an array length (must be 10 or greater): ");
- arrLength = kb.nextInt();
- }
- }
- int[]list1 = new int [arrLength];
- int[]list2 = new int [arrLength];
- for (int i = 0; i < arrLength; i++) {
- list1[i] = (int)(Math.random()*100+1);
- for (int j = 0; j < arrLength; j++) {
- list2[j] = (int)(Math.random()*100+1);
- }
- }
- int[]list = new int [arrLength*2];
- int c = 0;
- for (int i = 0; i < arrLength*2; i++) {
- if (i % 2 == 0)
- list[i] = list1[c];
- else
- c++;
- }
- c = 0;
- for (int i = 1; i < arrLength*2; i+=2) {
- list[i] = list2[c];
- c++;
- }
- c = 0;
- for (int i = 0; i < arrLength*2; i++) {
- for (int j = i + 1; j < arrLength*2; j++) {
- if (list[i] == list[j]) {
- list[j] = 0;
- }
- }
- }
- int arrLengthC = arrLength * 2;
- for (int i = 0; i < arrLengthC; i++) {
- if (list[i] == 0)
- arrLengthC --;
- }
- int[]listC = new int [arrLengthC];
- c = 0;
- for (int i = 0; i < list.length; i++) {
- if (list[i] != 0) {
- listC[c] = list[i];
- c++;
- }
- }
- System.out.println();
- System.out.print("First Array: ");
- for (int i = 0; i < arrLength; i++) {
- System.out.print(list1[i] + " ");
- }
- System.out.println();
- System.out.println();
- System.out.print("Second Array: ");
- for (int i = 0; i < arrLength; i++) {
- System.out.print(list2[i] + " ");
- }
- System.out.println();
- System.out.println();
- System.out.print("Merged Array: ");
- for (int i = 0; i < arrLengthC; i++) {
- if (listC[i] == 0)
- c = c;
- else
- System.out.print(listC[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement