java 如何从给定的整数值中获取 Alphabet?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12927074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:48:39  来源:igfitidea点击:

How to get Alphabet from the given integer value?

java

提问by M.M.RAM KUMAR

How to get alphabets by the numeric postion in java ?

如何通过java中的数字位置获取字母?

Suppose i have entered 1 then as a output i need to get A how can i get the alphabets position in java?

假设我输入了 1 然后作为输出我需要得到 A 我怎样才能在 java 中获得字母位置?

Thanks in advance.

提前致谢。

回答by Abubakkar

Try this

试试这个

int i = 1;
System.out.println((char)(i+'A'-1));

回答by Osiris

int charValue = 1; //this is the number you enter
char letter = (char)(charValue+64);  //this is the character you want

For lowercase letters, use (charValue+96)

对于小写字母,使用 (charValue+96)

回答by twodayslate

You could use a switch/case statementto manually get each letter however a better solution would be to use the ASCII table to get the letters.

您可以使用switch/case 语句手动获取每个字母,但更好的解决方案是使用 ASCII 表来获取字母。

ASCII Table: http://www.ascii-code.com/

ASCII 表:http: //www.ascii-code.com/

public char getLetter(int i)
{
  return (char) (i + 64);
}

The above function would return 'A' when i is 1

当 i 为 1 时,上述函数将返回 'A'

回答by epoch

You have letters/characters, think of them as positions in an array.

您有字母/字符,将它们视为数组中的位置。

int number = 0;
String[] array = new String[] {"a", "b", "c", "..."};
String letter = array[number + 1];