package com.itbaizhan.test.sort; import java.util.Arrays; public class Bubble { public static void main(String[] args) { int [] a = {2,4,1,3,9,6,5,7,0,8};//要排序的 int b = 1; int c = 2; swap(b,c); System.out.println(c+""); for (int i = 0 ; i<a.length;i++){ boolean DeterMine = true; for(int j = 0;j<a.length - i - 1;j++){ if (a[j]>a[j+1]){ int temp = 0; temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; swap(a[j],a[j+1]); DeterMine = false; } } if(DeterMine){ break; } System.out.println("第"+(i+1)+"次排序:"+ Arrays.toString(a)); } } static void swap(int a, int b){ int temp = 0; temp = a ; a = b; b = temp; } }
我的swap方法为什么不起效果