自己写的。
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.Scanner; import java.lang.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String str1 = in.nextLine(); String str2 = in.nextLine(); String res1 = ""; String res2 = ""; for (int i = 0; i < str1.length(); i++) { if (Character.isLetter(str1.charAt(i))) { if ('a' <= str1.charAt(i) && str1.charAt(i) <= 'z') { if (str1.charAt(i) == 'z') { res1 += "A"; } else { res1 += Character.toString(Character.toUpperCase((char)(str1.charAt(i) + 1))); } } else { if (str1.charAt(i) == 'Z') { res1 += "a"; } else { res1 += Character.toString(Character.toLowerCase((char)(str1.charAt(i) + 1))); } } } else { if (str1.charAt(i) == '9') { res1 += "0"; } else { res1 += Character.toString((char)(str1.charAt(i) + 1)); } } } for (int i = 0; i < str2.length(); i++) { if (Character.isLetter(str2.charAt(i))) { if ('a' <= str2.charAt(i) && str2.charAt(i) <= 'z') { if ('a' == str2.charAt(i)) { res2 += "Z"; } else { res2 += Character.toString(Character.toUpperCase((char)(str2.charAt(i) - 1))); } } else { if ('A' == str2.charAt(i)) { res2 += 'z'; } else { res2 += Character.toString(Character.toLowerCase((char)(str2.charAt(i) - 1))); } } } else { if (str2.charAt(i) == '0') { res2 += "9"; } else { res2 += Character.toString((char)(str2.charAt(i) - 1)); } } } System.out.println(res1); System.out.println(res2); } } }