题解 | 凯撒加密
凯撒加密
https://www.nowcoder.com/practice/006b7917d3784371a43cfbae01a9313d
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.hasNext()) { // 注意 while 处理多个 case int a = Integer.valueOf(in.nextLine()); String b = in.nextLine(); String z = "abcdefghijklmnopqrstuvwxyz"; for(int i = 0;i<b.length() ;i++){ int dex = z.indexOf(b.charAt(i)); int newIndex = dex + a; if(newIndex > z.length()-1){ newIndex = newIndex % z.length(); } System.out.print(String.valueOf(z.charAt(newIndex))); } } } }