解题思路
//题目表明条件:z = A , Z = a
//其余的26大小写字母都是该字母后面那个字母(char)(arr[i]+1)
//不属于26大小写字母直接输出
参考代码
package 文本加密;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
//将输入的字串转换为字符数组
char[] arr = sr.next().toCharArray();
sr.close();
for (int i = 0; i < arr.length; i++) {
//题目表明条件:z = A , Z = a
if (arr[i] == 'z') {
System.out.print('A');
}else if(arr[i] == 'Z'){
System.out.print('a');
//其余的26大小写字母都是该字母后面那个字母(char)(arr[i]+1)
}else if(arr[i] >= 'a' && arr[i] <= 'z' || arr[i] >= 'A' && arr[i] <= 'Z') {
System.out.print((char)(arr[i]+1));
}else {//不属于26大小写字母直接输出
System.out.print(arr[i]);
}
}
}
}