标签:system int stat 算法 public boolean bool out style
public static void main(String[] args) { int[] arr = {4, 2, 5, 9, 1, 6, 8}; boolean flag = false; for (int i = 1; i <= arr.length; i++) { System.out.println("第" + i + "轮:"); if (flag) { break; } flag = true; for (int j = 0; j < arr.length - i; j++) { System.out.println("第"+ j + "次:"); System.out.print("j:"+arr[j]+"\t"); System.out.println("j+1:"+arr[j+1]); System.out.println("比较前:"+Arrays.toString(arr)); if (arr[j] > arr[j + 1]) { arr[j] = arr[j] + arr[j + 1]; arr[j + 1] = arr[j] - arr[j + 1]; arr[j] = arr[j] - arr[j + 1]; flag = false; System.out.print("j:"+arr[j]+"\t"); System.out.println("j+1:"+arr[j+1]); System.out.println("比较后:"+Arrays.toString(arr)); } } } System.out.println("最后结果:" + Arrays.toString(arr)); }
标签:system int stat 算法 public boolean bool out style
原文地址:https://www.cnblogs.com/MoonASixpence/p/14814807.html