题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.*; public class Main { public static void main(String[] args) { String inttab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; String outtab = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890"; String s1, s2; Scanner scanner = new Scanner(System.in); // System.out.print("请输入两个字符串:"); // System.out.print("第一个字符串:"); s1 = scanner.nextLine(); // System.out.print("第二个字符串:"); s2 = scanner.nextLine(); scanner.close(); for (int i = 0; i < s1.length(); i++) { char c = s1.charAt(i); int index = inttab.lastIndexOf(c); s1 = s1.substring(0, i) + outtab.charAt(index) + s1.substring(i + 1); } for (int i = 0; i < s2.length(); i++) { char c = s2.charAt(i); int index = outtab.lastIndexOf(c); s2 = s2.substring(0, i) + inttab.charAt(index) + s2.substring(i + 1); } System.out.println(s1); System.out.println(s2); } }