How to add values from one array to another in reverse? [closed]

-2

Read a vector D of 10 elements. Create a vector E, with all the elements of D in order inverse, that is, the last element will become the first, the penultimate will be the second and so onwards. Write any vector D and any vector E. Can anybody help me ? One of the codes I tried:

int v[]=new int[3];
int z[]=new int[3]; 
for (int i = 0; i < v.length; i++) {
    v[i]=dado.nextInt();
}   
for (int i = z.length ; i >= 0; i++) {  
    z[i]=v[i];
}
for (int i = 0; i < z.length; i++) {
    System.out.println(z[i]);
}
    
asked by anonymous 24.06.2017 / 02:11

1 answer

0

An example:

int[] D = new int[] {1,2,3,4,5,6,7,8,9,10};

int[] E = new int[D.length];

int j = D.length - 1;


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

      E[j] = D[i]; // i começa em 0 e j começa em 9

      j--;

}

Any doubts you may have

    
24.06.2017 / 02:25