public class BubbleSort { /** * 冒泡排序方法 * * @param op * 需要排序的数组 */ public static void sortiere(int[] op) { for (int i = 0; i < op.length; i++) { for (int j = 0; j < op.length - i - 1; j++) { if (op[j] > op[j + 1]) { op[j] = op[j] ^ op[j + 1]; op[j + 1] = op[j] ^ op[j + 1]; op[j] = op[j] ^ op[j + 1]; } } } } /** * 测试方法 * * @param args */ public static void main(String[] args) { int[] op = { 5, 3, 1, 2, 4, 6 }; sortiere(op); System.out.println(Arrays.toString(op)); } }//源代码片段来自云代码http://yuncode.net