public class FenGe2 {
public static void main(String[] args) {
String s = "91 27 46 38 50";
//字符串分割
String[] s1 = s.split(" ");
int[] arr = new int[s1.length];
//字符数组转换为int型数组
for(int x = 0;x < s1.length;x++) {
arr[x] = Integer.parseInt(s1[x]);
System.out.print(arr[x]);
}
//冒泡排序输出
int[] arr1 = MaoPao(arr);
System.out.println();
for(int b = 0;b < arr1.length; b++) {
System.out.println(arr1[b]);
}
}
//冒泡排序法
public static int[] MaoPao(int[] arr) {
for(int y = 0;y < arr.length-1;y++) {
for(int x = 0;x < arr.length-1-y;x++) {
if(arr[x] > arr[x+1]) {
int temp = arr[x];
arr[x] = arr[x+1];
arr[x+1] = temp;
}
}
}
return arr;
}
}
数字类型字符串转换为排序后数组输出
最新推荐文章于 2024-08-18 22:29:23 发布