麻烦诸位给我写一个在数组里面第一个元素和最后一个元素互换位置的java小程序

2025-02-17 16:18:16
推荐回答(1个)
回答(1):

public class Test {
public static void main(String[] args) {
//交换之前
int[] score = {12, 42, 32, 1, 34, 53, 10};
int temp = score[0];
score[0] = score[score.length - 1];
score[score.length - 1] = temp;
//交换之后
for(int i = 0; i < score.length; i++){
System.out.print(score[i] + "\t");
}
}
}