黑马程序员技术交流社区

标题: 相互学习 [打印本页]

作者: 刘德坤    时间: 2015-10-10 10:21
标题: 相互学习
package com.itheima;

import java.util.Arrays;

public class Test26 {

        public static void main(String[] args) {
                // TODO Auto-generated method stub

                int[] arr = new int[]{2,4,5,6,8,7,3};
                bubbleSort(arr);
                System.out.println(Arrays.toString(arr));
        }
   
        public  static void bubbleSort(int[] arr){
                int temp = 0;
               
                for(int i=arr.length-1;i>0;--i){
                        for(int j=0;j<i;++j){
                                if(arr[j]>arr[j+1]){
                                        temp = arr[j];
                                        arr[j] = arr[j+1];
                                        arr[j+1] = temp;
                                }
                        }
                }
               
        }
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2