package package2;
import java.util.Arrays;
//:有一个字符串:“91 27 46 38 50”,
// 请写程序实现最终输出结果是:“27 38 46 50 91"
public class Test2 {
public static void main(String[] args) {
String str ="91 27 46 38 50";
String[] s = str.split(" ");
int[] arr = new int[s.length];
for (int i = 0; i < arr.length; i++) {
arr[i]=Integer.parseInt(s[i]);
}
Arrays.sort(arr);
StringBuilder sb =new StringBuilder();
for (int i = 0; i < arr.length; i++) {
if(i == arr.length-1){
sb.append(arr[i]);
}else {
sb.append(arr[i]).append(" ");
}
}
String result = sb.toString();
System.out.println(result);
}
}
标签:arr,27,46,50,38,91
From: https://www.cnblogs.com/knlf/p/16791910.html