- import java.util.Arrays;
- public class Solution {
- public static void main(String args[]) {
- int[] Array = { 3, 2, 1, 4, 5 };
- SwapArray testArray = new SwapArray();
- testArray.swapIntegers(Array, 0, 2);
- }
- }
- class SwapArray {
- /**
- * 给你一个数组和两个索引, 交换下标为这两个索引的数字
- */
- public void swapIntegers(int[] array, int index1, int index2) {
- int tmp = array[index2];
- array[index2] = array[index1];
- array[index1] = tmp;
- System.out.println(Arrays.toString(array));
- }
- }
来源: http://www.bubuko.com/infodetail-2988091.html