题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
String str=input.next();
char[] ch=str.toCharArray();
int len=ch.length;
for(int i=0;i<len;i++){
if(Character.isDigit(ch[i])){//是数字
//不做变换
}
if(ch[i]>='a'&&ch[i]<='z'){//是小写字母
//小写字母变成对应的数字
//1--1, abc--2, def--3, ghi--4, jkl--5, mno--6, pqrs--7, tuv--8 wxyz--9, 0--0,
if(ch[i]>='a'&&ch[i]<='c') {
ch[i]='2';
}else if(ch[i]>='d'&&ch[i]<='f') {
ch[i]='3';
}else if(ch[i]>='g'&&ch[i]<='i') {
ch[i]='4';
}else if(ch[i]>='j'&&ch[i]<='l') {
ch[i]='5';
}else if(ch[i]>='m'&&ch[i]<='o') {
ch[i]='6';
}else if(ch[i]>='p'&&ch[i]<='s') {
ch[i]='7';
}else if(ch[i]>='t'&&ch[i]<='v') {
ch[i]='8';
}else if(ch[i]>='w'&&ch[i]<='z') {
ch[i]='9';
}
}
if(ch[i]>='A'&&ch[i]<'Z'){
//大写字母变成小写之后+1
ch[i]=(char) (Character.toLowerCase(ch[i])+1);
}
if(ch[i]=='Z')
ch[i]='a';
}
for(int i=0;i<len;i++) {
System.out.print(ch[i]);
}
}
}