题解 | #简单密码# #JAVA#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); String[] KEYS = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; StringBuilder sb = new StringBuilder(); for (char c : str.toCharArray()) { //数字 if (Character.isDigit(c)) { sb.append(c); continue; //小写字母 } else if (Character.isLowerCase(c)) { for(int i=0; i<KEYS.length; i++) { if(KEYS[i].contains(String.valueOf(c))){ sb.append(i); } } //大写字母 } else if (Character.isUpperCase(c)) { int index = c - 'A'; index = (index + 1) % 26; sb.append((char)('a' + index)); } } System.out.println(sb); } }