+ 2
If array is {1,2,3,4,5,6,7,8,9,10} I should print it in this order {1,10,2,9,3,8,4,7,5,6}. How I do It in java?
2 Answers
+ 4
int x[]={1,2,3,4,5,6,7,8,9, 10};
System.out.print( "{");
for ( int i = 0, j = 9; i < 5; ++i, --j)
{
System.out.print( x[i] + ", ");
System.out.print(x[j]);
if (j != 5)
System.out.print( ", ");
}
System.out.print( "}\n");
0
If I don't know the number in the array how I do?