java 冒泡,手动输入会输出排序结果

来源:互联网 发布:视频配音软件 编辑:程序博客网 时间:2024/06/15 16:18
import java.io.* ;
import java.util.*;
public class maopao { 


  public static void logP(int a[]){
    int i =0;
     for (i = 0; i < a.length; i++) {
      System.out.print(a[i] + " ");


    }


  }
  public static void main(String[] args) {
    System.out.print("getIn");
    int i, j, n, temp;
    int length = 10;


    int a[] = new int [10];
    Scanner cin = new Scanner(new BufferedInputStream(System.in));
      
    for (i = 0; i<9; i++){
      a[i] = cin.nextInt();
    }


    n = a.length;
    for (j = 0; j < n; j++) {


      for (i = 0; i < n - j; i++) {


        try {


        // mathLength
          if (a[i] > a[i + 1]) {


            temp = a[i];


            a[i] = a[i + 1];


            a[i + 1] = temp;
          }


        } catch (Exception e) {


      // TODO: handle exception 


        }
      }
    }


   logP(a);


  }


}
0 0