今天看了SoftBean的博客感慨良多,发现自己对于java的学习只是停留在皮毛阶段,看了JDK1.5 API的split方法介绍后突然想到了以前的一道面试题。
 1class SplitDemo 
 2{
 3    public static void main(String[] args) 
 4    {
 5        String s1 = "This is a book";
 6        String[] str =  s1.split(" ");
 7        for (int i = 0;i<str.length ;i++ )
 8        {
 9            int t = str.length - i-1;
10            System.out.print(str[t]+" ");
11        }

12    }

13    
14}

15
结果是反转了字符串This is book,这样做是利用了split方法传入参数是正则表达式的特点,利用空格符分割了这句英文,得到的单词保存到字符数组str中,利用for从高到低的排列即得到了反转的英文句子。
posted on 2007-10-30 15:17 湘江夜游神 阅读(191) 评论(0)  编辑  收藏 所属分类: JAVA生活

只有注册用户登录后才能发表评论。


网站导航:
 

Locations of visitors to this page