题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s=in.next(); char[] arr=s.toCharArray(); int len=s.length(); String res=""; for(int i=0;i<len;i++){ char ch=arr[i]; if(ch>='a'&&ch<='z'){ if(ch>='a'&&ch<='c')res+='2'; else if(ch>='d'&&ch<='f')res+='3'; else if(ch>='g'&&ch<='i')res+='4'; else if(ch>='j'&&ch<='l')res+='5'; else if(ch>='m'&&ch<='o')res+='6'; else if(ch>='p'&&ch<='s')res+='7'; else if(ch>='t'&&ch<='v')res+='8'; else if(ch>='w'&&ch<='z')res+='9'; } else if(ch>='A'&&ch<'Z'){ char t= (char)(ch+32+1); res+=t; } else if(ch=='Z')res+='a'; else res+=ch; } System.out.println(res); } }