import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.next(); String str1 = encode(str); System.out.println(str1); } public static String encode(String text) { String result; char[] chars = text.toCharArray(); char[] chRes = new char[chars.length]; for (int i = 0; i < chars.length; i++) { if ((chars[i] >= 'A' && chars[i] < 'Z') || (chars[i] >= 'a' && chars[i] < 'z')) { chRes[i] = (char) (chars[i] + 1); } else if (chars[i] == 'z') { chRes[i] = 'a'; } else if (chars[i] == 'Z') { chRes[i] = 'A'; } else { chRes[i] = chars[i]; } } result = String.valueOf(chRes); return result; } }
输入一个字符串,将其中所有的大写和小写字母改成该字母的下一个字母,z 的下一个字母为 a。JAVA
于 2022-11-30 15:14:40 首次发布