题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.Scanner;
public class Main {
//HJ21 简单密码
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
char[] input = sc.nextLine().toCharArray();
StringBuilder sb = new StringBuilder();
for (Character s :input){
if(s>='A'&&s<='Z'){
if(s=='Z'){
s='a';
}else {
s = (char) (s + 1);
}
sb.append(s);
continue;
}
if(s>='a'&&s<='c'){
s='2';
}else if(s>='d'&&s<='f'){
s='3';
}else if(s>='g'&&s<='i'){
s='4';
}else if(s>='j'&&s<='l'){
s='5';
}else if(s>='m'&&s<='o'){
s='6';
}else if(s>='p'&&s<='s'){
s='7';
}else if(s>='t'&&s<='v'){
s='8';
}else if(s>='w'&&s<='z'){
s='9';
}
sb.append(s);
}
String output = sb.toString().toLowerCase();
System.out.println(output);
}
}
}