public class String_Test06 {
public static void main(String[] args) {
String string = "-7 0 4 12 13 30 99 100";
// 切割字符串转换为字符串数组
String[] arr = string.split(" ");
int[] arr2 = new int[arr.length];
// 设置等长的字符串数组
for (int i = 0; i < arr.length; i++) {
arr2[i] = Integer.parseInt(arr[i]);
}
// 对整型数组排序
Arrays.sort(arr2);// Arrays可以对任意类型进行排序
// 遍历数组进行连接
String str = "";
for (int i = 0; i < arr2.length; i++) {
/* if (i == arr2.length - 1) {
str = str + arr2[i];
} else {*/
str = str + arr2[i] + " ";
}
System.out.println(str.trim());
}
}
|
|