码迷,mamicode.com
首页 > 编程语言 > 详细

面试之冒泡排序代码实现

时间:2017-09-20 22:06:43      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:system.in   stat   next   ati   log   int()   class   []   for   

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();
    }
}

 

面试之冒泡排序代码实现

标签:system.in   stat   next   ati   log   int()   class   []   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!