您的位置:首页 > 编程语言 > Java开发

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

2015-08-11 20:05 351 查看
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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: