public class ReverseArray {
public static void main(String[] args) {
//e.g {0,1,2,3,4,5,6,7} should return {7,6,5,4,3,2,1,0}
int[] input = {0,1,2,3,4,5,6,7};
for(int k:input)
System.out.print(k);
int i = -1;
int j = input.length;
int tmp = 0;
while (i++<j--)
{
tmp = input[i];
input[i] = input[j];
input[j] = tmp;
}
System.out.println();
for(int k:input)
System.out.print(k);
}
}
public static void main(String[] args) {
//e.g {0,1,2,3,4,5,6,7} should return {7,6,5,4,3,2,1,0}
int[] input = {0,1,2,3,4,5,6,7};
for(int k:input)
System.out.print(k);
int i = -1;
int j = input.length;
int tmp = 0;
while (i++<j--)
{
tmp = input[i];
input[i] = input[j];
input[j] = tmp;
}
System.out.println();
for(int k:input)
System.out.print(k);
}
}
No comments:
Post a Comment