public static void main(String[] args) {
		
		int[] A = {1, 3, 4, 6,8,10, 17, 34} ;
		int[] B = {2, 8, 17, 33, 44, 66, 89, 100, 123}; 

		int largest = A[A.length-1] > B[B.length-1]?  A[A.length-1] : B[B.length-1];
		int smallest = A[A.length-1] < B[B.length-1]?  A[A.length-1] : B[B.length-1];
		
		int i=0,j=0;
		
		while(smallest != largest) {
			if(A[i] == B[j]) {
				smallest = A[i];
				i++;
				j++;
			} else if(A[i] < B[j]) {
				System.out.print(A[i]+" ");
				smallest = A[i];
				i++;
			} else {
				smallest = B[j];
				System.out.print(B[j]+" ");
				j++;
			}
			
			if(i>=A.length) {
				for (; j < B.length; j++) {
					System.out.print(B[j] + " ");
					smallest = B[j];
				}
			}
			
			if(j>=B.length) {
				for (; i < A.length; i++) {
					System.out.print(A[i] + " ");
					smallest = A[i];
				}
			}
			
		}
	}