数组元素逆序 (就是把元素对调)------------------
public class Demo
{
public static void main(String[] args) {
int[] arr ={5,54,6,87,65,12,2};
for(int i=0;i<(arr.length/2);i++)
{
int temp = arr[i];
arr[i] = arr[arr.length-i-1];
arr[arr.length-i-1] = temp;
}
for(int i=0;i<arr.length;i++){
sop(arr[i]);
}
}
public static void sop(Object obj)
{
System.out.println(obj);
}
} |
|