输入一行电报文字,将字母变成其下一字母(如’a’变成’b’……’z’变成’a’其它字符不变)

import java.util.Scanner;
public class Main {
public static void main(String[] age) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
print(n);
}
public static void print(String x) {
{
char arr[] = new char[100];
for (int i = 0; i < x.length(); i++)
{
if (x.charAt(i) >= 'a' && 'z' > x.charAt(i) || x.charAt(i) >= 'A' & 'Z' > x.charAt(i))
{
arr[i] = (char) (x.charAt(i) + 1);
System.out.print(arr[i]);

else if (x.charAt(i) == 'z') { //z输出a
arr[i] = 'a';
System.out.print(arr[i]);

else if (x.charAt(i) == 'Z') {    //Z输出A
arr[i] = 'A';
System.out.print(arr[i]);

else
System.out.print(x.charAt(i));    //其它字符
}
}
}
}

你可能感兴趣的:(java)