import java.util.Arrays;
public class TestPrit {
/**
* 需求把字符串"-34 29 76 11 27"中的数据排序并输出。
分析:把字符串通过空格进行拆分,然后将元素拿出来依次转换为Integer对象,打印输出.
*/
public static void main(String[] args) {
String st = "-34 29 76 11 27";
String[] st1 = st.split(" ");
int[] arr = new int[st1.length];
for (int i = 0; i < st1.length; i++) {
arr[i] = Integer.parseInt(st1[i]);
}
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
|
|