如何在java中获取字母的数字位置? [英] How to get numeric position of alphabets in java?
本文介绍了如何在java中获取字母的数字位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在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
这篇关于如何在java中获取字母的数字位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文