如何在Java中反转int数组
下面的程序反转一个int数组。
示例
public class Tester {
public static void main(String[] args) {
int[] numbers = {1,2,3,4,5};
//交换数字直到中点出现
for (int start = 0, end = numbers.length - 1;
start <= end;
start++, end--) {
int temp = numbers[start];
numbers[start]=numbers[end];
numbers[end]=temp;
}
for(int number: numbers){
System.out.print(number + " ");
}
}
}输出结果
5 4 3 2 1
热门推荐
10 祝愿女孩成长祝福语简短
11 兔年祝福语简短100字
12 孙媳妇祝福语简短
13 对学姐的简短祝福语
14 结业蛋糕男生祝福语简短
15 高考已上岸祝福语简短
16 简短祝福语蛋糕简笔画
17 人民子弟春节祝福语简短
18 给舍友送祝福语简短