+ 2
Using java array
input [1,2,3,4,5,6] output [6,1,5,2,4,3]
2 Answers
+ 2
excellent try ...result also good but if you try only single array to get result
0
Maybe something like this?
public class Program
{
public static void main(String[] args)
{
int[] src = {1,2,3,4,5,6}; // source
int[] dst = new int[6]; // destination
int l = src.length - 1;
// This loop takes elements from src
// and copy it into dst.
for(int i = 0, idx = 0; i < 3; ++i)
{
dst[idx++] = src[l - i];
dst[idx++] = src[i];
}
// Prints the elements of src & dst
for(int v : src)
System.out.print(v + " ");
System.out.println();
for(int v : dst)
System.out.print(v + " ");
}
}
Hth, cmiiw