按从小到大的顺序排列。0.60.610.6990.6110.601?
1个回答
展开全部
value输出排序结果:0.60.601.610.6110.6990
public static void main(String[] args){
String value = "0.60.610.6990.6110.601";
value = sortSmallToBig(value);
System.out.print("value输出排序结果:" + value);
}
public static String sortSmallToBig(String value) {
String[] arr = value.split(".");
for (int i = 2; i < arr.length; i++) {
for (int j = 1; j < arr.length-1; j++) {
float ai = Float.parseFloat("0."+arr[i]);
float aj1 = Float.parseFloat("0."+arr[i+1]);
if(ai>aj1) {
String temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
value = arr[0];
for (int j = 1; j < arr.length; j++){
value += "." + arr[j];
}
return value;
}
public static void main(String[] args){
String value = "0.60.610.6990.6110.601";
value = sortSmallToBig(value);
System.out.print("value输出排序结果:" + value);
}
public static String sortSmallToBig(String value) {
String[] arr = value.split(".");
for (int i = 2; i < arr.length; i++) {
for (int j = 1; j < arr.length-1; j++) {
float ai = Float.parseFloat("0."+arr[i]);
float aj1 = Float.parseFloat("0."+arr[i+1]);
if(ai>aj1) {
String temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
value = arr[0];
for (int j = 1; j < arr.length; j++){
value += "." + arr[j];
}
return value;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询