array

array

..how to make this program??


what is the length of 1st array:5
what is the length of 2nd array:4

enter a number for 1st array: 4
enter a number for 1st array: 6
enter a number for 1st array: 2
enter a number for 1st array: 1
enter a number for 1st array: 7
=================================
enter a number for 2nd array: 3
enter a number for 2nd array: 5
enter a number for 2nd array: 9
enter a number for 2nd array: 8
=================================

the final array is: 1 2 3 4 5 6 7 8 9
View Answers

October 5, 2010 at 12:46 PM

Hi Friend,

Try the following code:

import java.util.*;
class ArrayExample1
{
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)
{
Scanner input=new Scanner(System.in);
System.out.println("What is the length of 1st array: ");
int arr1size=input.nextInt();
System.out.println("What is the length of 2nd array: ");
int arr2size=input.nextInt();
int arr1[]=new int[arr1size];
int arr2[]=new int[arr2size];

for(int i=0;i<arr1.length;i++){
System.out.println("enter a number for 1st array: ");
arr1[i]=input.nextInt();
}

for(int i=0;i<arr2.length;i++){
System.out.println("enter a number for 2nd array: ");
arr2[i]=input.nextInt();
}

int arr[] = (int[]) merge(arr1, arr2);
Arrays.sort(arr);

for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}

}
}

Thanks









Related Tutorials/Questions & Answers:
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
Advertisements
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  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  How do i insert elements into an array up to a limit from...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size]; System.out.println("Enter Array Elements: "); for(int i=0;i<
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  can we create an array of size 1 lakh in java programming
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  wap to calculate reverse of 10 elements in an array?  ...(); } System.out.print("Array is: "); for(int i=0;i<arr.length;i...(); System.out.print("After reversing, Array is: "); for(int i=arr.length-1;i>=0
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... is an example that store some integers into an array and find the occurrence of each number from the array. import java.util.*; public class SearchNumberOccurrence
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
reserved. Use a one-dimensional array of primitive type Boolean to represent the seating chart of the cinema theater. Initialize all the elements of the array... the corresponding elements of the array to true to indicate that the seat is no longer
PHP Push Array to Array
PHP Push Array to Array  array_push() function using array in PHP
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
length in array
length in array  wat s length in array
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
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 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
array ADT
array ADT  Write a program using array_ADT to retrieve a list of URLs from a file. In your program take an array index as the input and delete the entry corresponding to that index
Array and input
Array and input  if this is my array int briefcases [ ]={1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; i want to ask user to input one of the above numbers then i want to print the array without the number
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
array declaration
array declaration  String propArray = []; is this declaration correct?   Hi Friend, No, This is the wrong way.ADS_TO_REPLACE_1 Array..., visit the following links:ADS_TO_REPLACE_2 Integer Array String Array ThanksADS
Array Name
Array Name  How To Set Value in Two-Dimension ArrayList
length in array
length in array  hi wat is length in array and where s it used
array string
array string  how to sort strings with out using any functions
using array
using array  Circular left shift array element by one position
using array
using array  Circular left shift array element by one position
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Array copy
Array copy  Hello all. could someone telle me how to copy an array (holding random numbers) to a new array...( then make randomnumbers on this new array ) but without changing the excisting array ? last . possibility
Array search
Array search  Need a program which performs a searching operation on a one dimensional array called NUM, which is an N-element array stored in a file... for the search operation. he value with one or more of the array items. Search begins
ARRAY and STACK
ARRAY and STACK  hello, What is the difference between ARRAY... that is first entered would be the last removed. In Array the items can be entered or removed in any order.   a stack is simply a special case of an array
Array in C
Array in C  Respected Sir, How can an array be an lvalue, if we can't assign to it? How can I set an array's size at run time? How can I avoid fixed-sized arrays? help me sir
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: ââ?¬Å...?¬Â?. ii) Write a loop that displays the contents of each element in the array
array list
array list  How to get repeate occurence values from database table in java by using arraylist
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array

Ads