对10个数进行排序。

public class Example28 {
    public static void main(String[] args) {
        int[] s = { 5, 7, 6, 1, 9, 4, 2, 3, 8 };
        BubbleSort(s);
    }

public static void BubbleSort(int[] a) {
        System.out.print("原数组为:");
        for (int i : a) {
            System.out.print(i+" ");
        }
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        System.out.print("\n排序后的数组为:");
        for (int i : a) {
            System.out.print(i+" ");
        }
    }
}

Java经典编程题50道之二十八的更多相关文章

  1. Java经典编程题50道之二十五

    一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. public class Example25 {    public static void main(Stri ...

  2. Java经典编程题50道之二十

    有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和. public class Example20 {    public static void ma ...

  3. Java经典编程题50道之二十六

    请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母. public class Example26 {    public static void main(Stri ...

  4. Java经典编程题50道之二十九

    求一个3*3矩阵对角线元素之和. public class Example29 {    public static void main(String[] args) {        int[][] ...

  5. Java经典编程题50道之二十四

    有5个人坐在一起,问第5个人多少岁,他说比第4个人大2岁.问第4个人岁数,他说比第3个人大2岁. 问第三个人,他说比第2人大两岁.问第2个人, 说比第一个人大两岁.最后问第一个人,他说是10岁. 请问 ...

  6. Java经典编程题50道之二十二

    利用递归方法求5!. public class Example22 {    public static void main(String[] args) {        int n = 5;   ...

  7. Java经典编程题50道之二十七

    求100之内的素数. public class Example27 {    public static void main(String[] args) {        prime();    } ...

  8. Java经典编程题50道之二十三

    给一个不多于5位的正整数,要求:①求它是几位数:②逆序打印出各位数字. public class Example23 {    public static void main(String[] arg ...

  9. Java经典编程题50道之二十一

    求1+2!+3!+...+20!的和. public class Example21 {    public static void main(String[] args) {        sum( ...

随机推荐

  1. Flexible Box布局基础知识详解

    1.基本概念,借用阮一峰老师的一张图: 容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis).主轴的开始位置(与边框的交叉点)叫做main start,结束位置叫 ...

  2. Linux Server release 7.3 更换阿里网络yum源

    查看当前系统下的yum源 [root@localhost ~]# rpm -qa |grep yum yum-3.4.3-150.el7.noarch yum-utils-1.1.31-40.el7. ...

  3. cpuimage 开源之

    前年学习opengl做的一个小东西. 原本计划将gpuimage 的算法一个一个转写成cpu版本 c,c++ 版本. gpuimage 项目参考: https://github.com/BradLar ...

  4. linkin大话数据结构--List

    List:Collection子接口 List是有序的集合,集合中每个元素都有对应的顺序序列.List集合可使用重复元素,可以通过索引来访问指定位置的集合元素(顺序索引从0开始),List集合默认按元 ...

  5. convert图像格式批量转换

    问题:利用GMT绘制生成了eps格式的图像,为了将图像插入到word中,且保持较高的分辨率,利用convert进行图像格式转换,将eps转换成tiff格式. code:  $i ${name}.tif ...

  6. Linux时间转标准时间

    [root@nhserver2 ~]# date -d '1970-1-1 0:0:0 GMT + 1394592071 seconds'Wed Mar 12 10:41:11 CST 2014

  7. 【转】5 Best Place to Learn Linux – Linux Tutorial Sites

    Linux have amazed every tech guy and make them curious to hands on Linux. Many of us not feel Linux ...

  8. Python selenium 一个节点两个关联input

    HTML代码: 一个节点两个关联input  多出现于密码框 先需要模拟点击进入第一个input,才能激活第二个input. 代码: driver.find_element_by_name('Text ...

  9. .net中关于Windows窗体程序和Web网站程序调用自己的服务

    在.NET Framework 4.0创建服务是中没有像3.5那样的选择新建-网站-ASP.NET Web服务模块,但在4.0中可以选择 新建-网站-ASP.NET空网站-选中项目右键添加新项- 选择 ...

  10. xBIM 插入复制功能

    目录 xBIM 应用与学习 (一) xBIM 应用与学习 (二) xBIM 基本的模型操作 xBIM 日志操作 XBIM 3D 墙壁案例 xBIM 格式之间转换 xBIM 使用Linq 来优化查询 x ...