Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


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


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

Advertisement
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  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
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
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  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...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
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
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: import java.io....]=Integer.parseInt(br.readLine()); } System.out.println("Array Elements
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
Hibernate 1 - Hibernate
Hibernate 1  what is a fetchi loading in hibernate?i want source code?plz reply
Tags in struts 1
Tags in struts 1   I have problem in Include tag in Struts this tag using but it is not work Please Explain
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
java code7 of 1
java code7 of 1  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g ?· t in t time units
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
String Exercises 1 - Answers
Java: String Exercises 1 - Answers Answers to the String Exercises 1. 3 -- s refers to exactly the same string as a. ERROR -- t is a local variable, and it must be assigned a value first. "1abc" -- + means concatenation
New Page 1
the output as per condition. javascript_array_loop_through.html <...;= 1; i <= 9; i++){   for(var j = 1
WEBSERVICES=1 - WebSevices
WEBSERVICES=1  I have develop webservices through wsad classes i dont want like this.I want like Create simple class to acess webservice is it possibule to create simple class to acess the webservice?  Hi Friend
task 1 - Java Beginners
task 1  Please write a Java client that send a small letters string to a Java server which convert it to uppercase letters and send it back to the client. Please submit both the client and server programs  Hi Friend
Ajax Question 1
Ajax Question 1  I am having 3 fields in jsp they are Fieldname,Fieldtype,Required. If i enter Fieldname as studentid,Fieldtype as checkbox,Required as true(i.e., mandatory field as *).It should store their details in database
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
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
que 1 - Java Beginners
que 1  WAP to enter a sentence & count the no. of times a particular word occurs in it.Display the frequency of the searched word. eg- input:the quick brown fox jumps over the lazy dog. word to be searched:the output
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Try
contructors 1&test
contructors 1&test   how do i Create a class named Box that includes integer data fields for length, width and height. Create three constructors... created with length 10 and width 15. Box created with length 1, width 2
Logging Tutorial - Part 1
Logging Tutorial - Part 1 2000-12-14 The Java Specialists' Newsletter [Issue 003] - Logging part 1 Author: Dr. Heinz M. Kabutz If you are reading... information. Logging Part 1 of ... (haven't decided yet ;-) While we
data insertion and fetch 1
data insertion and fetch 1  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type
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
Advertisements
 

 

 

DMCA.com