把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间。
输入例子:
AkleBiCeilD
输出例子:
kleieilABCD
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNextLine()) {
String string = scn.nextLine();
String L = "[a-z]";
String H = "[A-Z]";
Pattern patternL = Pattern.compile(L);
Pattern patternH = Pattern.compile(H);
Matcher matcherL = patternL.matcher(string);
Matcher matcherH = patternH.matcher(string);
StringBuffer str1 = new StringBuffer();
while (matcherL.find()) {
str1.append(matcherL.group());
}
while (matcherH.find()) {
str1.append(matcherH.group());
}
System.out.println(str1.toString());
}
}
}
注意把类名改为Main