天天看点

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

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

  }

}