Computer Science, asked by irenerebeccamaria72, 4 months ago

Write a program to store 6 integer numbers in array1 and 4 numbers  in array2.  Create a 3rd array to store the elements of both array1 and array2. (i.e. merge the 2 arrays)   

Answers

Answered by BrainlyProgrammer
3

Question:-

Write a program to store 6 integer numbers in array1 and 4 numbers  in array2.  Create a 3rd array to store the elements of both array1 and array2. (i.e. merge the 2 arrays)   

Answer:-

This is a very easy Question....Here is the approach

Code:-

package Coder;

import java.util.*;

public class Array {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int a[]=new int[6]; //Array1

int b[]=new int[4]; //Array2

int c[]=new int[10]; //Array3

System.out.println("Enter elements of first array");

for(int i=0;i<6;i++)

{

a[i]=sc.nextInt();

}

System.out.println("Enter elements of second array");

for(int i=0;i<4;i++)

{

b[i]=sc.nextInt();

}

System.out.println("Merged array:-");

for(int i=0;i<10;i++)

{

if(i<6)

c[i]=a[i];

else

c[i]=b[i-6];

}

for(int i=0;i<10;i++)

{

System.out.println(c[i]);

}

}

}

Variable Description:-

  1. a:- to accept 6 numbers from the user as input
  2. b:- to accept 4 numbers from the user as input
  3. c:- to print the combined(merged) array of a and b
  4. i:- loop variable

•Output Attached

Attachments:
Similar questions