Combining two different arrays in java -


i wanted combine 2 arrays , not know wrong code keeps giving me results:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 exception in thread "main" java.lang.arrayindexoutofboundsexception: 20     @ javaday3.arrayexpanding.main(arrayexpanding.java:17) 

the results want view :

    0     1     2     3     4     5     6     7     8     9     0     0     0     0     0     0     0     0     0     0 

please me find wrong code: wanted combine 2 arrays manually using loops

package javaday3;     public class arrayexpanding {         public static void main(string[] args) {                     int ages [] = {0,1,2,3,4,5,6,7,8,9}; // first array         for( int = 0; < ages.length; i++) {                   int temp [] = new int [20];// bigger , 2nd array          for(int ix = 0; ix < temp.length; ix++) {                     for(int ixx = 0; ixx <= temp.length; ixx++) {             temp [0] = ages [0] ;                            system.out.println(temp[ixx]);           }          }         }       } } 

should add or remove please me using eclipse , taking java

if want put element in ages[] temp[], can follow these steps.

  1. let have 2 arrays follows.

    int ages[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int temp[] = new int[20]; 

2.then iterate ages array , assign value of each element temp array

    for(int = 0; < ages.length; i++) {         temp[i]=ages[i];     } 

3. temp array contains want. can print temp array either

    for(int i=0;i<temp.length;i++){         system.out.println(temp[i]);     } 

or

    system.out.println(arrays.tostring(temp)); 

eg:

    int ages[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};     int temp[] = new int[20];     (int = 0; < ages.length; i++) {         temp[i]=ages[i];     }     for(int i=0;i<temp.length;i++){         system.out.println(temp[i]);     } 

Comments