首页 > 编程语言 > 详细

面试之冒泡排序代码实现

时间:2017-09-20 21:24:13      阅读:214      评论:0      收藏:0      [点我收藏+]
public class Sort {
    public static void sort() {
        Scanner input = new Scanner(System.in);
        int sort[] = new int[10];
        int temp;
        System.out.println("请输入10个排序的数据:");
        for (int i = 0; i < sort.length; i++) {
            sort[i] = input.nextInt();
        }
        for (int i = 0; i < sort.length - 1; i++) {
            for (int j = 0; j < sort.length - i - 1; j++)             {
                if (sort[j] < sort[j + 1]) {
                    temp = sort[j];
                    sort[j] = sort[j + 1];
                    sort[j + 1] = temp;
                }
            }
        }
        System.out.println("排列后的顺序为:");
        for(int i=0;i<sort.length;i++){
            System.out.print(sort[i]+"   ");
        }
    }
    public static void main(String[] args) {
        sort();
    }
}

 

面试之冒泡排序代码实现

原文:http://www.cnblogs.com/MJyc/p/7565015.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!