题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
String s1=sc.nextLine();
String s2=sc.nextLine();
StringBuilder ss1=new StringBuilder();
StringBuilder ss2=new StringBuilder();
for(int i=0;i<s1.length();i++){
char c=s1.charAt(i);
if(Character.isLetter(c)){
if(Character.isUpperCase(c)){
if(c=='Z') ss1.append('a');
else{
ss1.append(Character.toLowerCase((char)(c+1)));
}
} else if(c=='z')ss1.append('A');
else ss1.append(Character.toUpperCase((char)(c+1)));
}else{
if(c=='9')
ss1.append('0');
else ss1.append((char)(c+1));
}
}
System.out.println(ss1.toString());
for(int i=0;i<s2.length();i++){
char c=s2.charAt(i);
if(Character.isLetter(c)){
if(Character.isUpperCase(c)){
if(c=='A') ss2.append('z');
else{
ss2.append(Character.toLowerCase((char)(c-1)));
}
} else if(c=='a')ss2.append('Z');
else ss2.append(Character.toUpperCase((char)(c-1)));
}else{
if(c=='0')
ss2.append('9');
else ss2.append((char)(c-1));
}
}
System.out.println(ss2.toString());
}
}