题解 | #密码翻译# Java实现
密码翻译
https://www.nowcoder.com/practice/136de4a719954361a8e9e41c8c4ad855
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String s = in.nextLine(); StringBuilder builder = new StringBuilder(); for(int i = 0;i < s.length();i++){ char ch = s.charAt(i); //System.out.println("ch = "+ch); if(Character.isLetter(ch)){ char c = ' '; if(ch == 'z'){ c = 'a'; }else if(ch == 'Z'){ c = 'A'; }else{ c = (char)(ch+1); } builder.append(c); }else{ builder.append(ch); } } System.out.println(builder.toString()); } } }