array 1

array 1

WAP to input values in 2 arrays and merge them to array M.
View Answers

February 15, 2010 at 12:42 PM

Hi Friend,

Try the following code:

import java.util.*;
class MergeArray{
public static int[] merge(int [] ... arr) {
int arrSize = 0;
for (int[] array : arr) {
arrSize += array.length;
}
int[] result = new int[arrSize];
int j = 0;
for (int[] array : arr) {
for (int s : array) {
result[j++] = s;
}
}
return result;
}
public static void main(String[] args) {
int[] array1 = new int[5];
System.out.println("Enter 5 numbers");
Scanner input = new Scanner(System.in);
for (int i = 0; i < array1.length; i++) {
array1[i] = input.nextInt();
}
int[] array2 = new int[5];
System.out.println("Enter 5 numbers");
for (int i = 0; i < array2.length; i++) {
array2[i] = input.nextInt();
}
int M[] = (int [])merge(array1,array2);
System.out.println("Merged Array is: ");
for(int i=0;i<M.length;i++){
System.out.println(M[i]);
}

}
}

Thanks









Related Tutorials/Questions & Answers:
array 1 - Java Beginners
array 1  WAP to input values in 2 arrays and merge them to array M...; for (int[] array : arr) { arrSize += array.length; } int[] result = new int[arrSize]; int j = 0; for (int[] array : arr
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
Advertisements
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
Array
Array  How do i insert elements into an array up to a limit from command prompt using SOP statement.like Enter range:3 Enter elements: 1 5 3  ...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size
Array
Array  can we create an array of size 1 lakh in java programming
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
array
(); System.out.print("After reversing, Array is: "); for(int i=arr.length-1;i>=0...array  wap to calculate reverse of 10 elements in an array?  ...(); } System.out.print("Array is: "); for(int i=0;i<arr.length;i
Array's
Array's  I have to finish an "order page". that checks 2 dropdown boxes and a set of radio buttons and put the results into a set of textboxes, 1 line at a time, then calculate a total. I know I need to create an array, but I'm
array
array  Hi i have array like {1,2,3,4,,5,5,6,6} then how can i display 1 time , 5 - 2times, 3- 2times thank kalins naik   Here is an example that store some integers into an array and find the occurrence of each
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend... Scanner(System.in); int array[]=new int[5]; System.out.println("Enter
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
Array
the following alternatives: Please type 1 for Twin Seat and Please type 2 for Normal Seat. If the user types 1, your application should assign a Twin Seat numbered from 1 to 5. If the user types 2, your application should assign a Normal Seat
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
array
array  How to store the results of mysql query in an array... qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select... store the result in array
array
array  how to getting values and storing values in array by using datainputstream?   Hi Friend, Try the following code:ADS_TO_REPLACE_1...("Array Elements are: "); for(int i=0;i<arr.length;i
array
array  0 1 2 3 4 5 6 7 8 9 can i have the code... twoD[][] = new int[4][]; twoD[0] = new int[4]; twoD[1] = new int[3]; twoD[2] = new int[2]; twoD[3] = new int[1]; int i,j,k = 0; for(i=0;i<4;i++) for(j=i;j<
array
array  write a program in java which input n ,a natural number less than 12 and prints the natural number from 1 to n to the power 2 in the form of a spiral.the spiral should move in on anti clockwise direction starting from
PHP Push Array to Array
PHP Push Array to Array  array_push() function using array in PHP
array to string
array to string  hello how to assign value from array to string. nsstring *abc = [array objectAtindex:1];   you can use this codeADS_TO_REPLACE_1 NSString *abc = [NSString stringWithString:[array objectAtIndex:i
PHP Array Push Array
-Array-Push.html ADS_TO_REPLACE_3 PHP Array Push Array Example 1: <?php... the second array into first array is: Array ( [0] => 0 [1] => 1...] => Array ( [0] => n [1] => e
Javascript array
of array: "); var arr=new Array for(var i=0;i<arrsize;i++){ var j=i+1; var...;b>Array Reverse</b><br>"); for(var i=arr.length-1;i>=0;i... the array size from the user Input the array elements from the user display
ARRAY TUTORIAL
fragments to illustrate your answer. Q6 - Array indices in Java always begin with 1...? Array Exercise: 1. Given an array of 100 integers , to be populated by random...ARRAY TUTORIAL  PLEASE HELP ME ANSWER THESE ARRAY TUTORIAL Q1
ARRAY TUTORIAL
fragments to illustrate your answer. Q6 - Array indices in Java always begin with 1...? Array Exercise: 1. Given an array of 100 integers , to be populated by random...ARRAY TUTORIAL  PLEASE HELP ME ANSWER THESE ARRAY TUTORIAL Q1
using array
using array  display 10 digit number using array and print pyramid. 1 1 1 1 1 1 1 1 1 1 1 1
Array sort
Array sort  Program that uses a function to sort an array of integers
array example
array example  giving input from outside for array example
problem 1 - Java Beginners
problem 1   Hi, please help me!!!! How can i code in java using Two-dimensional Arrays? This question is related to the one i posted before... 96 102 109 120 You will be using a 2-D Array to write this program
array sort - Java Beginners
array[], int len){ for (int i = 1; i < len; i++){ int j = i; int tmp = array[i]; while ((j > 0) && (array[j-1] > tmp...array sort  hi all, can anybody tell me how to sort an array
length in array
length in array  wat s length in array
Array element comparison
:- Assuming size as 5. Therefore ; Array 1 be 10 , 5 , 6 Array 2 be 12 , 6 , 8 Array 3... Array 1 to all other except Array 1 , Array 2 to all other except Array 2...Array element comparison  I have arrays of Length(L) , width(W
array problem
array problem  An integer array a has 19 elements. What is the value of the middle element after the following codes is executed? int i, j,n=19; for (i=0; i for(i=0, j=n-1; i<=j; i++, j--) a[(i+j)/1] -= (a[i]+a[j])/2
Java array
Java array   How can one prove that the array is not null but empty
array ADT
array ADT  Write a program using array_ADT to retrieve a list of elements from a file
array ADT
array ADT  Write a program using array_ADT to retrieve a list of elements from a file
Array of structure
Array of structure  create employment details with necessary field using array of structure
Array Sorter
Array Sorter  I need a program that will ask the user to either "Enter an Array" or to "Exit the program" If the user want to enter an array the are asked to enter ten numbers. Then those ten numbers are stored in an array
Java programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program... ? this method gets the marks from the user, places them in a local array and returns that array to main; ?findSmallest ? this method returns the smallest

Ads