代码如下 求大神指点...
package cn.itcast;
//将字符串s 从小到大排列顺序
public class Demo1 {
public static void main(String[] args) {
String s="12,13,54,79,-26,98,100";
String[] arr = s.split(",");
for (int i = 0; i < arr.length; i++) {
// System.out.print(arr[i]+" ");
for (int j = 0; j < arr.length; j++) {
if(arr[i]>arr[j]){ //此行报错 因为 arr[i]和arr[j]是String类型 不能用>.
String x=arr[i];
arr[i]=arr[j];
arr[j]=x;
}
}
for (int a = 0; a < arr.length; a++) {
System.out.print(arr[a]+" ");
}
}
}
}
|