packagetest;importjava.util.Scanner;public classexam13 {public static voidmain(String[] args) {
Scanner scanner= newScanner(System.in);while(scanner.hasNext()) {
String str=scanner.nextLine();//char[] pwd = str.toCharArray();//System.out.println(truepwd(str).toString());
System.out.println(truepwd2(str));
}
scanner.close();
}//方法1:if判断
public staticStringBuilder truepwd(String str) {
StringBuilder sbBuilder= newStringBuilder();for (int i = 0; i < str.length(); i++) {char ch =str.charAt(i);if (ch >= 'A' && ch < 'Z') {
ch= (char) (ch + 1 - ('A' - 'a'));
}else if (ch == 'Z') {
ch= 'a';
}else if (ch >= 'a' && ch <= 'z') {if (ch == 'a' || ch == 'b' | ch == 'c') {
ch= '2';
}else if (ch == 'd' || ch == 'e' || ch == 'f') {
ch= '3';
}else if (ch == 'g' || ch == 'h' || ch == 'i') {
ch= '4';
}else if (ch == 'j' || ch == 'k' || ch == 'l') {
ch= '5';
}else if (ch == 'm' || ch == 'n' || ch == 'o') {
ch= '6';
}else if (ch == 'p' || ch == 'q' || ch == 'r' || ch == 's') {
ch= '7';
}else if (ch == 't' || ch == 'u' || ch == 'v') {
ch= '8';
}else if (ch == 'w' || ch == 'x' || ch == 'y' || ch == 'z') {
ch= '9';
}
}
sbBuilder.append(ch);
}returnsbBuilder;
}//方法2:使用正则表达式
public staticString truepwd2(String str) {
StringBuffer sBuffer= newStringBuffer(str);for (int i = 0; i < str.length(); i++) {char ch =sBuffer.charAt(i);if (ch >= 'A' && ch < 'Z') {
ch= (char) (ch + 1 - ('A' - 'a'));
}else if (ch == 'Z') {
ch= 'a';
}else if (ch >= 'a' && ch <= 'z') {if (String.valueOf(ch).matches("[abc]")) {
ch= '2';
}else if (String.valueOf(ch).matches("[def]")) {
ch= '3';
}else if (String.valueOf(ch).matches("[ghi]")) {
ch= '4';
}else if (String.valueOf(ch).matches("[jkl]")) {
ch= '5';
}else if (String.valueOf(ch).matches("[mno]")) {
ch= '6';
}else if (String.valueOf(ch).matches("[pqrs]")) {
ch= '7';
}else if (String.valueOf(ch).matches("[tuv]")) {
ch= '8';
}else if (String.valueOf(ch).matches("[wxyz]")) {
ch= '9';
}
}
sBuffer.setCharAt(i, ch);
}returnsBuffer.toString();
}
}