How to add values from one array to another inversely?

Asked

Viewed 360 times

-2

Read a vector D of 10 elements. Create an array E, with all elements of D in the order inverse, ie, the last element will become the first, the penultimate will be the second and so from above. Write all vector D and all vector E. Could someone 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]);
}
  • And what is your doubt before the exercise?

  • I’m not able to add The values of vector v in z inversely, could help me ?

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 doubt dispose

  • Please do not unnecessarily use highlight formatting in the text. I noticed that in all your answers you tried to use highlight with the character #.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.