标签:and main 16px 数组 临时 变量 system stat temp
public static void main(String[] args) {
int[] a = new int[5];
for (int i = 0; i < 5; i++) {
a[i] = (int) (Math.random()*100);
System.out.print(a[i]+" ");
}
/* 反转数组,再输出,只借助一个临时变量*/
int temp;
// 以中间数为对称轴,下标加起来和为a.length-1的两个数互换位置
for(int j=0; j<a.length/2; j++){
temp = a[j];
a[j] = a[a.length-1-j];
a[a.length-1-j] = temp;
}
System.out.println("");
for(int g=0; g<a.length; g++){
System.out.print(a[g] + " ");
}
}
标签:and main 16px 数组 临时 变量 system stat temp
原文地址:https://www.cnblogs.com/leemlzm/p/12044613.html