輸入任意字串,將其中的數字分別進行輸出(使用正則運算式實作)。
例如:輸入字串為”a12b3cc5de67a”,輸出12 3 5 67。
將字串“go wuhan go china”轉變成每個單詞首字母大寫,如“Go Wuhan Go Chian”(提示:使用正則運算式中的分組實作)。
uj5u.com熱心網友回復:
for exampleMatcher m = Pattern.compile(“(\\d+)”).matcher(“a12b3cc5de67a”);
while(m.find()) {
System.out.printf(“%s “, m.groug(1));
}
m = Pattern.compile(“(\\w)”).matcher(“go wuhan go china”);
while(m.find()) {
String s=Character.toUpperCase(m.group(1).charAt(0)) + m.group(1).substring(1);
System.out.printf(“%s “, s);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/124634.html
標籤:Eclipse
下一篇:maven依賴的問題
