对String s = "11.1,56.1,2.9,34.3,1.03,24.2" 不能使用jdk自带排序方法

来源:互联网 发布:时标网络计划图总时差 编辑:程序博客网 时间:2024/05/17 23:54
public class Test {public static void main(String[] args) {sortStr("11.1,56.1,2.9,34.3,1.03,24.2");}private static void sortStr(String s) {String str[] = s.split(",");double d[] = new double[str.length];try {for (int i = 0; i < str.length; i++) {d[i] = Double.valueOf(str[i]);}for (int i = 0; i < d.length - 1; i++) {for (int j = 0; j < d.length - i - 1; j++) {if (d[j] < d[j + 1]) {double temp = d[j];d[j] = d[j + 1];d[j + 1] = temp;}}}System.out.println(d.toString());} catch (Exception e) {System.out.println(e);}}}

原创粉丝点击