Posted in 面试题 onNovember 09, 2012
import java.util.*;
public class bycomma{
public static String[] splitStringByComma(String source){
if(source==null||source.trim().equals(“”))
return null;
StringTokenizer commaToker = new StringTokenizer(source,”,”);
String[] result = new String[commaToker.countTokens()];
int i=0;
while(commaToker.hasMoreTokens()){
result[i] = commaToker.nextToken();
i++;
}
return result;
}
public static void main(String args[]){
String[] s = splitStringByComma(“5,8,7,4,3,9,1″);
int[] ii = new int[s.length];
for(int i = 0;i
ii[i] =Integer.parseInt(s[i]);
}
Arrays.sort(ii);
//asc
for(int i=0;i
System.out.println(ii[i]);
}
//desc
for(int i=(s.length-1);i>=0;i–){
System.out.println(ii[i]);
}
}
}
public class bycomma{
public static String[] splitStringByComma(String source){
if(source==null||source.trim().equals(“”))
return null;
StringTokenizer commaToker = new StringTokenizer(source,”,”);
String[] result = new String[commaToker.countTokens()];
int i=0;
while(commaToker.hasMoreTokens()){
result[i] = commaToker.nextToken();
i++;
}
return result;
}
public static void main(String args[]){
String[] s = splitStringByComma(“5,8,7,4,3,9,1″);
int[] ii = new int[s.length];
for(int i = 0;i
}
Arrays.sort(ii);
//asc
for(int i=0;i
}
//desc
for(int i=(s.length-1);i>=0;i–){
System.out.println(ii[i]);
}
}
}
现在输入n个数字,以逗号,分开;然后可选择升或者降序排序;按提交键就在另一页面显示按什么排序,结果为,提供reset
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@