A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
比如输入A或B或C 都转换成2 怎么实现啊???
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
比如输入A或B或C 都转换成2 怎么实现啊???
Map<String,Integer> map=new HashMap<String,Integer>();
String[] arr={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y"};
for(int i=0;i<arr.length;i++){
map.put(arr[i], (i/3)+2);
}
Scanner in=new Scanner(System.in);
while(true){
System.out.println("请输入字母");
String str=in.nextLine();
if(str.matches("[A-Z]")&&!str.equals("Q")&&!str.equals("Z")){
System.out.println(str+"的对应值是:"+map.get(str));
}else{
System.out.println("输入错误,请重新输入!");
}
}
//A
int charAZ = 65;
Map map = new HashMap();
int value = 2;
int count = 0;for(int i = 0;i<26;i++){
map.put(char(charAZ)+"" , value + count/3 );
count++;}
于是我们可以这么算设输入值为X
(X-65)/3 + 2 得到的就是输出值。