zoukankan      html  css  js  c++  java
  • 冒泡排序

    实现数组在排序方面的应用。有键盘输入一组整数,用冒泡法进行排序并输出。

    import  java.io.*;
    
    public class Array_Sort_Demo {
        public static void main(String[] args)throws IOException{
            BufferedReader buf;
            String str;
            int i,j,temp;
            int a[];
            int count=0;
            a=new int[8];
            System.out.println("input data:");
            for(i=0;i<a.length;i++){
                buf=new BufferedReader(new InputStreamReader(System.in));
                str=buf.readLine();
                a[i]=Integer.parseInt(str);
            }
            for(i=0;i<a.length;i++){
                if(i==0)
                    System.out.print(a[i]);
                else
                    System.out.print(","+a[i]);
            }
            System.out.println("");
            System.out.println("**********Sorted Course**********");
            for(i=1;i<a.length;i++){
                count++;
                for(j=0;j<a.length-i;j++)
                    if(a[j]>a[j+1]){
                        temp=a[j];
                        a[j]=a[j+1];
                        a[j+1]=temp;
                    }
                System.out.print("第"+count+"趟:");
                for(j=0;j<a.length;j++){
                    if(j==0)
                        System.out.print(a[j]);
                    else
                        System.out.print("."+a[j]);
                }
                System.out.println("");
            }
            System.out.println("**********Sorted Result**********");
            for(j=0;j<a.length;j++){
                if(j==0)
                    System.out.print(a[j]);
                else
                    System.out.print("."+a[j]);
            }
            System.out.println("");
            System.out.println("");
        }
    
    }

  • 相关阅读:
    react: redux-devTools
    react: menuService
    react: navigator
    react style: 二级菜单
    spark复习笔记(5):API分析
    spark复习笔记(4):spark脚本分析
    maven 打包Scala代码到jar包
    spark复习笔记(3)
    mongoDB学习笔记(2)
    sparkStreaming复习笔记(1)
  • 原文地址:https://www.cnblogs.com/ljs-666/p/7814430.html
Copyright © 2011-2022 走看看