A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 刘德坤 中级黑马   /  2015-10-10 10:21  /  205 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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;
                                }
                        }
                }
               
        }
}
您需要登录后才可以回帖 登录 | 加入黑马