展开全部
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class MaoPaoPaiXu {
public static void main(String[] args) throws Exception {
System.out.println("请输入62616964757a686964616fe59b9ee7ad9431333361323464要输入的正整数个数:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String num = br.readLine();
int len = Integer.parseInt(num);
int[] source = new int[len];
System.out.println("请输入正整数,每个正整数之间用\",\"分割:");
String sourceString = br.readLine();
br.close();
String[] sourceStrs = sourceString.split(",");
if (sourceStrs.length != len) {
System.out.println("输入的正整数个数和输入的正整数数量不匹配。");
return;
}
for (int i = 0; i
source[i] = Integer.parseInt(sourceStrs[i]);
}
//冒泡排序
int temp = 0;
for (int i = source.length-1; i > 0; --i) {
for (int j = 0; j
if (source[j+1]
temp = source[j];
source[j] = source[j+1];
source[j+1] = temp;
}
}
}
System.out.println("冒泡排序后的数组内容:");
StringBuffer sb = new StringBuffer();
for (int string : source) {
sb.append(string+",");
}
System.err.println(sb.toString());
}
}
运行后的内容:
请输入要输入的正整数个数:
6
请输入正整数,每个正整数之间用","分割:
876,234,123,2,32,12
冒泡排序后的数组内容:
2,12,32,123,234,876,