题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String s1 = in.next();
String s2 = in.next();
char[] c = s1.toCharArray();
char[] c1 = s2.toCharArray();
for(int i = 0; i<c.length; i++){
if(c[i]>='0' && c[i]<='9'){
c[i] = (char)((int)c[i] + 1);
if(c[i] > '9'){
c[i] = '0';
}
}else if(c[i]>='a' && c[i]<='z'){
c[i] = (char)((int)c[i] - 32 + 1);
if(c[i]>'Z'){
c[i] = 'A';
}
}else if(c[i]>='A' && c[i]<='Z'){
c[i] = (char)((int)c[i] + 32 + 1);
if(c[i]>'z'){
c[i] = 'a';
}
}
}
for(int i = 0; i<c1.length; i++){
if(c1[i]>='0' && c1[i]<='9'){
c1[i] = (char)((int)c1[i] - 1);
if(c1[i] < '0'){
c1[i] = '9';
}
}else if(c1[i]>='a' && c1[i]<='z'){
c1[i] = (char)((int)c1[i] - 32 -1);
if(c1[i]<'A'){
c1[i] = 'Z';
}
}else if(c1[i]>='A' && c1[i]<='Z'){
c1[i] = (char)((int)c1[i] + 32 -1);
if(c1[i]<'a'){
c1[i] = 'z';
}
}
}
System.out.println(s1.copyValueOf(c));
System.out.println(s2.copyValueOf(c1));
}
}
}