如何在java中获取字母的数字位置?
How to get numeric position of alphabets in java ?
假设通过命令提示我输入了abc然后作为输出我需要得到123我怎么能得到java中字母的数字位置?
Suppose through command prompt i have entered abc then as a output i need to get 123 how can i get the numeric position of alphabets in java?
提前致谢。
推荐答案String str = "abcdef"; char[] ch = str.toCharArray(); for(char c : ch) { int temp = (int)c; int temp_integer = 96; //for lower case if(temp<=122 & temp>=97) System.out.print(temp-temp_integer); }
输出:
123456
123456
@Shiki for Capital / UpperCase字母使用以下代码:
@Shiki for Capital/UpperCase letters use the following code:
String str = "DEFGHI"; char[] ch = str.toCharArray(); for(char c : ch) { int temp = (int)c; int temp_integer = 64; //for upper case if(temp<=90 & temp>=65) System.out.print(temp-temp_integer); }输出: 456789