题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] split = s.split("");
for (int i = 0; i < split.length; i++) {
char c = split[i].charAt(0);
if (split[i].matches("[abc]")){
s = s.replace(c, '2');
}else if (split[i].matches("[def]")){
s = s.replace(c,'3' );
}else if (split[i].matches("[ghi]")){
s = s.replace(c,'4' );
}else if (split[i].matches("[jkl]")){
s = s.replace(c,'5' );
}else if (split[i].matches("[mno]")){
s = s.replace(c,'6' );
}else if (split[i].matches("[pqrs]")){
s = s.replace(c,'7' );
}else if (split[i].matches("[tuv]")){
s = s.replace(c,'8' );
}else if (split[i].matches("[wxyz]")){
s = s.replace(c,'9' );
}
}
String lowerCase = s.toLowerCase();
String[] split1 = lowerCase.split("");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < split1.length; i++) {
if (split1[i].matches("[z]")){
split1[i]="a";
} else if (split1[i].matches("[a-y]")){
char c = split1[i].charAt(0);
Integer in = Integer.valueOf(c);
Integer in1 = in+1;
int i1 = in1.intValue();
char i11 = (char) i1;
split1[i]=i11+"";
}
sb = sb.append(split1[i]);
}
String code = sb.toString();
System.out.println(code);
}
}
