Scanner sc = new Scanner(System.in);
System.out.print("请输入五个数,用空格隔开:");
String results = sc.nextLine();
String pat = "\\s+";
Pattern p = Pattern.compile(pat);
String s[] = p.split(results);
int S[] = new int[s.length];
for (int x = 0; x < s.length; x++) {
S[x] = Integer.parseInt(s[x]);
}
for (int i = 0; i < S.length - 1; i++) {
for (int j = 1; j < S.length - i; j++) {
if (S[j] < S[j - 1]) {
int M = S[j - 1];
S[j - 1] = S[j];
S[j] = M;
}
}
}
记录免忘记正则
最新推荐文章于 2024-05-19 21:34:53 发布