将字母变成其下一字母

    科技2025-04-27  11

    输入一行电报文字,将字母变成其下一字母 例如: a 变成 b ,b 变成 c ,c 变成 d…z 变成 a,其他的字符不变

    样例输入: ab

    样例输出: bc

    import java.util.Scanner; public class xx { public static void main(String[] args) { Scanner s=new Scanner(System.in); String str=s.next(); for(int i=0;i<str.length();i++){ if(str.charAt(i)=='z'){ System.out.print("a"); }else{ System.out.print((char)(str.charAt(i)+1)); } } } }
    Processed: 0.009, SQL: 8