题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s1=in.next(); String s2=in.next(); int len1=s1.length(); int len2=s2.length(); String res1=""; String res2=""; for(int i=0;i<len1;i++){ char c=s1.charAt(i); if(c<'z'&&c>='a')res1+=(char)(c-32+1); else if(c=='z')res1+="A"; else if(c<'Z'&&c>='A')res1+=(char)(c+32+1); else if(c=='Z')res1+="a"; else if(c>='0'&&c<'9')res1+=(char)(c+1); else if(c=='9')res1+="0"; } for(int i=0;i<len2;i++){ char c=s2.charAt(i); if(c<='z'&&c>'a')res2+=(char)(c-32-1); else if(c=='a')res2+="Z"; else if(c<='Z'&&c>'A')res2+=(char)(c+32-1); else if(c=='A')res2+="z"; else if(c>'0'&&c<='9')res2+=(char)(c-1); else if(c=='0')res2+="9"; } System.out.println(res1); System.out.println(res2); } }