public static void main(String[] args) {
int[] array = {1, 5, 6, 9, 7, 8};
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
System.out.println("===============");
/*
初始化语句:int min = 0, max = array.length;
条件判断:min <max;
步进表达式:min++, m--;
循环体:用第三个变量倒手
*/
for (int min = 0, max = array.length - 1; min < max; min++, max--) {
int temp = array[min];
array[min] = array[max];
array[max] = temp;
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
} |
|