当前位置: 代码迷 >> J2ME >> 两道java编程题,求解,该如何处理
  详细解决方案

两道java编程题,求解,该如何处理

热度:3925   发布时间:2013-02-25 21:34:09.0
两道java编程题,求解
18.String s = "113@ ere qqq yyui"
请输出所有子串
113
ere
qqq
yyui


19. 编写一个程序,将下面的一段文本中的各个单词的字母顺序翻转,
“To be or not to be",将变成"oT eb ro ton ot eb."。



------解决方案--------------------------------------------------------
汗,贴错地方了

Java code
    public static void main(String[] args) throws Exception {        String s = "113@ ere qqq yyui";        s=s.replaceAll("[^a-zA-Z 0-9]", "");        for (String str: s.split(" ")) {            System.out.println(str);        }                        //末尾标点是不是不要反转?        s = "To be or not to be.";//"oT eb ro ton ot eb."。        StringBuffer sBuffer = new StringBuffer();        for (String str: s.split("\\s")) {            char punctuate=' ';            char[] chars = str.toCharArray();            for (int i = chars.length-1;i>=0;i--) {                if (i==chars.length-1 && !Character.isLetter(chars[i])) {                    punctuate = chars[i];                    continue;                }                sBuffer.append(chars[i]);            }            sBuffer.append(punctuate);        }        System.out.println(sBuffer);    }
  相关解决方案