Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[] firstArray = new int[10000];
- System.out.println("Enter the values for the first array up to 10000 values, enter zero or a negative number to quit");
- int values = scan.nextInt();
- boolean check = true;
- while (check) {
- for (int x = 0; x < firstArray.length; x++) {
- if (values > 0) {
- firstArray[x] = values;
- values = scan.nextInt();
- } else {
- check = false;
- }//end of if/else
- }//end of for loop
- }// end of while loop
- System.out.println("Enter the values for the second array up to 10000 values, enter zero or a negative number to quit");
- int values2 = scan.nextInt();
- int[] secArray = new int[10000];
- boolean check2 = true;
- while (check2) {
- for (int y = 0; y < secArray.length; y++) {
- if (values2 > 0) {
- secArray[y] = values2;
- values2 = scan.nextInt();
- } else {
- check2 = false;
- }//end of if/else
- }//end of for loop
- }// end of while loop
- System.out.println("First Array:");
- for(int z = 0; z < firstArray.length; z++) {
- if(firstArray[z] > 0) {
- System.out.print(firstArray[z] + " ");
- }
- }//end of for loop
- System.out.println("\n\nSecond Array:");
- for(int a = 0; a < secArray.length; a++) {
- if(secArray[a] > 0) {
- System.out.print(secArray[a] + " ");
- }
- }//end of for loop
- int min = 0;
- int min2 = 0;
- boolean check3 = true;
- boolean check4 = true;
- if(check3) {
- for(int b = 0; b <firstArray.length; b++) {
- if(firstArray[b] >= min) {
- min = firstArray[b];
- if(firstArray[b+1] < min && firstArray[b+1] > 0) {
- System.out.println("\n\nERROR: Array not in correct order");
- check3 = false;
- check4 = true;
- }//end of nested if
- } //end of if/else
- }//end of for
- for(int c = 0; c < secArray.length; c++) {
- if(secArray[c] >= min2) {
- min2 = secArray[c];
- if(secArray[c+1] < min2 && secArray[c+1] > 0){
- System.out.println("\n\nERROR: Array not in correct order");
- check3 = false;
- check4 = true;
- }//end of nested if
- }//end of if/else
- }//end of for
- }//end of for loop
- System.out.print("\n\n");
- int[] fin = new int[20000];
- int xx = 0;
- for(int d = 0; d <10000; d++) {
- if(firstArray[d] > 0) {
- fin[d]+=firstArray[d];
- } else {
- fin[d] += secArray[xx];
- xx++;
- }//end of if/else
- }//end of for loop
- Arrays.sort(fin);
- System.out.println("Merged Array:");
- for (int i = 0; i < fin.length; i++) {
- if(fin[i] >0) {
- System.out.print(fin[i] + " ");
- }//if loop
- }//for loop
- }//end of program
- }//end of program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement