java编程题:现在输入n个数字,以逗号,分开;然后可选择升或者降序排序;按提交键就在另一页面显示按什么
1个回答
展开全部
import java.util.*;
public class ByCommond{
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.length; i++) {
ii[i]=Integer.parseInt(s[i]);
}
Arrays.sort(ii);
for (int j = 0; j < ii.length; j++) {
System.out.println(ii[j]);
}
for (int i=(s.length-1);i>=0;i--){
System.out.println(ii[i]);
}
}
}
public class ByCommond{
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.length; i++) {
ii[i]=Integer.parseInt(s[i]);
}
Arrays.sort(ii);
for (int j = 0; j < ii.length; j++) {
System.out.println(ii[j]);
}
for (int i=(s.length-1);i>=0;i--){
System.out.println(ii[i]);
}
}
}
追问
好吧 网上coppy的 还是谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询