Tuesday, November 27, 2012

It is important to know this example that is, How to merge both array in single variable !!!!


Below program provide you the reference regarding merging both array in other ! 

_______________________________________


public class Array {


public static void main(String[] args) {
// TODO Auto-generated method stub

int A [] = {1,2,3,4,5};

int B [] = {6,7,8,9,10};

int C[][] = {A,B}; 


int la = A.length;
int lb = B.length;




System.out.print("ARRAYS in A: ");

for(int x = 0; x<la;x++){
System.out.print("  "+A[x]);
}



System.out.println(" \n");



System.out.print
("ARRAYS in B: ");


for(int y=0;y<lb;y++){
System.out.print(" "+B[y]);
}



System.out.println("\n ");




System.out.print("Arrays in C: ");

for(int i = 0; i<C.length;i++){

for(int j= 0;j<C[i].length;j++){
System.out.print(C[i][j]);
}
     }
}
}
_______________________________________

Output:

ARRAYS in A:   1  2  3  4  5 

ARRAYS in B:  6 7 8 9 10

Arrays in C: 12345678910
________________________________________

In above programme, we use two dimensional array C[] []  to merge the A[] and B[] single array !!!

Hope you enjoy this simple but important programme !

No comments:

Post a Comment