a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 50|回复: 0

[考试试题] JAVA试题:JAVA编程模拟题:排序和金额转换

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
1.此刻输入n个数字,以逗号,分隔;然后可选择升或者降序排序;按提交键就在另一页面显示按什么排序,结不美观为,供给reset
( }! m% }5 g. R9 Y9 R0 r2 A( |import java.util.*; - I  F# L  }. Y; H  l
public class bycomma{
9 v, J; i( c6 G, Y public static String[] splitStringByComma(String source){
* I# W4 v( H0 a3 u9 j   if(source==null||source.trim().equals(""))
' M( |: o- F( t# P6 Q    return null;
6 k3 }+ n8 v& A/ C   StringTokenizer commaToker = new StringTokenizer(source,","); / _4 t8 _& C, F" I" o. _+ c$ N4 j
   String[] result = new String[commaToker.countTokens()];   b& r1 O: D9 T& l
   int i=0;   d6 V) e; B0 ?
   while(commaToker.hasMoreTokens()){
" Z% z2 B+ y6 A, ~! |" ?0 E    result = commaToker.nextToken(); , D! Q, ^2 f5 l1 ^, t
    i++;
: d7 x1 X% q) y   }
( b& O8 n3 ?7 F" ]% E   return result; # f* c$ T! P& \9 e* a( B
}
2 s8 k( _2 v# }( H public static void main(String args[]){
: Z; o4 w- J6 K9 t7 a String[] s = splitStringByComma("5,8,7,4,3,9,1"); ' `2 ]- g: N6 O: Q5 R% ~
int[] ii = new int[s.length];
' }, v& m+ M. K7 N) X7 A2 p for(int i = 0;i
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-22 04:53 , Processed in 0.227833 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表