mudita sinha
array 1
1 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners

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 Pages:
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
Array
Array  can we create an array of size 1 lakh in java programming
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  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
reversing, Array is: "); for(int i=arr.length-1;i>=0;i...array  wap to calculate reverse of 10 elements in an array?  ...++ ) { arr[i]=input.nextInt(); } System.out.print("Array
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
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  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
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
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
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
New Page 1
the output as per condition. javascript_array_loop_through.html <...;= 1; i <= 9; i++){   for(var j = 1
Solving task 1 by 1 from bundle of task data
Solving task 1 by 1 from bundle of task data  Hello and namaste guys... set.what should i do so that the solve code solve data 1 by 1?do i need to use array?what kind of 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
Java programming 1 - Java Beginners
Java programming 1  Thx sir for reply me ^^ err how bout if using scanner class or further method to solve that code? instead of using array?   Hi friend, For more information on Scanner class visit to : http
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 to string
array to string  hello how to assign value from array to string. nsstring *abc = [array objectAtindex:1];   you can use this code NSString *abc = [NSString stringWithString:[array objectAtIndex:i]]; where i
Javascript array
arr=new Array for(var i=0;i<arrsize;i++){ var j=i+1; var element... the array size from the user Input the array elements from the user display the array elements reverses it and display   Hello Friend, Try this: <
More than 1 preparedStatement object - Java Beginners
More than 1 preparedStatement object  Hey but I want to use more than... =?"); pst1.setString(1, "Delhi"); pst1.setString(2, "angelina1"); pst1.addBatch(); pst1.setString(1, "Mumbai
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
PHP Array Push Array
Array Example 1: <?php $array1=array(0,1,23,45,36,8); echo"<...: Elements of the first array is : Array ( [0] => 0 [1] => 1 [2... of the second array is : Array ( [0] => n [1] => e [2] =>
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
Array in Java
Array in Java  public class tn { public class State...(){ State[] s = new State[10]; int [] i = new int[10]; i[0] = 1; //right s[0].p1 = 1; //error NullPointerException
java array
java array Two cells is a matrix will be called connected if they are adjacent... of all integers in that island. 1 0 0 0 1 0 1 2 2 1 0 2 0 0 0 1 In above example matrix, there are two islands
program in array
that initializes an array with ten random integers and then prints four lines of output...[]=new int[10]; System.out.println("Array of Random Numbers...]); } } System.out.println("On reversing, Array changes
Create Array ??
Create Array ??   Question in e-clips program: Part 1. Array... stores list of â??PhoneEntryâ?? objects. Use an array of size (MAXSIZE = 1000... interface that has been used in Part 1, but this time with the class â??MyLinkedListâ
HELP WITH ARRAY
[100]; int nItems=0; int j; int searchId; arr[0]= 11; arr[1...--) arr[k] = arr[k+1]; nItems... that the user input didn't match match with the number in the array boxes
Sorting the array
candidates in a talent contest. The program should use a String array to hold the names of the 5 candidates and an integer array to record the number of votes for each... they wish to vote for (in the range 0 ? 4), until -1 is entered, which signifies
Help With an Array
Help With an Array  So what Im trying to do is write an array... trying to do is almost combine the two to create a larger array declaration...++) {System.out.print ("Enter student " + (index+1) + " name :"); names[index
programes on array
in an array of an integer b. write a program to convert decimal no. to binary... iv) find transpose of an matrix   1) import java.util.*; class...]; for(int i=1;i < arr.length;i++){ if(arr[i] > maxValue
Java arraycopy example- 1
;intArray = new int[] { 1, 2, 3, 4, 5 
Create Multiplication Table from 1 to 10
;(int j=1; j<array[i].length; j++) { array[i][j] = i... to create multiplication table from 1 to 10. For this purpose, we have created 2-dimensional Array 'array[][]' and using the for loop, we have stored the product
Help With an Array
sum; int salesPerson=-1; int salesPerson1 = -1; int number; int x; Scanner... for salesperson " + (i+1) + ": "); sales[i] = scan.nextInt... = 0; for (int i=0; i { System.out.println(" " + (i+1) + " " + sales[i
PHP Array
Example 1: <?php echo"An array with similar datatype"... with similar datatype array(3) { [0]=> string(5) "These" [1...; bool(true) [4]=> string(1) "v" } Array in PHP with Example
PHP Array
define array in both the ways...  Method 1.  $myArray[] = "Hi...The meaning of an array is almost same in all programming language but there could be different ways to define it. In simple words an array is used
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 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
Array example
;Array();   array[0] = "Ajay";   array[1... Array example       Array is an object that hold the data of similar type. The length
PHP Array
_array[0] = "Apple"; $fruit_array[1] = "Banana"; $fruit_array... to create simple array: // Create a simple array. $my_array = array(1, 2, 3, 4, 5,6,7,8); You can also create using following code: $a = array(1 => '
array manipulation - Java Beginners
array manipulation  We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array
array - Java Beginners
for 1st array: 1 enter a number for 1st array: 7... ================================= the final array is: 1 2 3 4 5 6 7 8 9   Hi Friend, Try... array:5 what is the length of 2nd array:4 enter a number for 1st array: 4
Array /string based problem....
[] selectionSort(char[] array) { for (int i = 1; i < array.length; i++) { int...]+" "); } } static String[] selectionSort(String[] array) { for (int i = 1...Array /string based problem....  thanx to help me.but again a problem
array - Java Beginners
a number for 1st array: 2 enter a number for 1st array: 1 enter a number... a number for 2nd array: 8 ================================= the final array is: 1...*; and no function,,, what is the length of 1st array:5 what is the length of 2nd
Array in Java
to assign a value in an array: int[0] = 50; int[1] = 60; int[2] = 70; int[3...An Array is the static memory allocation that holds a fixed number of values of same type in memory. The size or length of an array is fixed when the array
Array in Java - Java Beginners
to smallest. For example: For the array -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3...Array in Java  Please help me with the following question. Thank you. Write a program that reads numbers from the keyboard into an array of type
ARRAY - Java Beginners
++; } } else if(array[i]==array[j]){ num = 1; } } if(num != 1){ System.out.println(array[i]+" = "+ count...ARRAY  How To Find Out Unique Elements Of Given Array

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.