Answer to Question #290518 in Java | JSP | JSF for Akesh

Question #290518

Write a program to create 2 single dimension arrays in order to store 5 numbers and 6 numbers respectively. Then merge those values of both the array into third array so that the values of the first array will be kept first from left to right followed by values of second array again from left to right. Then display those values of the merged(third) array.

Use only java.util.* package

The output of the program must be like below:

Enter 5 numbers for first array

34 57 879 21 9

Enter 6 numbers for second array

12 3 4567 23 31 98

Values of first array from left to right followed by second array again from left to right

34 57 879 21 9

12 3 4567 23 31 98

Values of merged array

34 57 879 21 9 12 3 4567 23 31 98


1
Expert's answer
2022-01-25T08:49:16-0500
import java.util.*;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		System.out.println("Enter 5 numbers for first array: ");
		int numbers1[] = new int[5];
		for (int i = 0; i < 5; i++) {
			numbers1[i] = keyBoard.nextInt();
		}
		System.out.println("Enter 6 numbers for second array: ");
		int numbers2[] = new int[6];
		for (int i = 0; i < 6; i++) {
			numbers2[i] = keyBoard.nextInt();
		}
		int[] numbers3 = new int[numbers1.length + numbers2.length];
		System.arraycopy(numbers1, 0, numbers3, 0, numbers1.length);
		System.arraycopy(numbers2, 0, numbers3, numbers1.length, numbers2.length);


		System.out.println("Values of merged array");
		for (int i = 0; i < numbers3.length; i++) {
			System.out.print(numbers3[i] + " ");
		}


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS