题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.*;
public class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
StringBuilder stringBuilder = new StringBuilder();
String str = sc.nextLine();
str = str.replaceAll("([a|b|c])","2");
str = str.replaceAll("([d|e|f])","3");
str = str.replaceAll("([g|h|i])","4");
str = str.replaceAll("([j|k|l])","5");
str = str.replaceAll("([m|n|o])","6");
str = str.replaceAll("([p|q|r|s])","7");
str = str.replaceAll("([t|u|v])","8");
str = str.replaceAll("([w|x|y|z])","9");
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Y'){
stringBuilder.append((char)(str.charAt(i) + 32 + 1));
}else if (str.charAt(i) == 'Z'){
stringBuilder.append('a');
}else
stringBuilder.append(str.charAt(i));
}
System.out.println(stringBuilder);
}
}