-1

I am looking to convert numbers to their corresponding letter in the alphabet.

java1234
  • 17
  • 1
  • 2
  • [Try this Post](http://stackoverflow.com/questions/5328996/java-change-int-to-ascii) Question was already asked to stackoverflow – Lukas A Apr 10 '17 at 14:28
  • The term alphabet is not very precise and the system of a number's corresponding letter is unclear. I am familiar with the English alphabet of 26 letters from to A-Z and the idea of numbering them 1 to 26. However, Java uses Unicode for text datatypes. Unicode has at least two forms for those letters (lowercase and uppercase) as well as a number of specialized scripts with some or all of those letters. It also has its own [numbering system](http://www.unicode.org/charts/nameslist/index.html) for every character (usually written in hexadecimal like U+0041). Is that what you mean? – Tom Blodget Apr 10 '17 at 18:21

3 Answers3

3

As seen here alphabetical characters start from either 65 or 97 (depending on capitalization) so you just add either 64 or 96 to your value and then just cast it to a char.

Random rand = new Random(); 
int TargetNumber = rand.nextInt(25) + 1;
char TargetChar = (char) (TargetNumber+64);
Nasto
  • 428
  • 2
  • 11
0

Try this

Random rand = new Random(); 
int TargetNumber = rand.nextInt(25) + 1;
char c = (char)(TargetNumber+96);

This adds 96 to the generated value, and then type casts it into a char. This works for a-z. To make it through A-Z replace 96, by 64.

dumbPotato21
  • 5,669
  • 5
  • 21
  • 34
-2

i think you can do this:

char a = (char)20;
victor
  • 802
  • 7
  • 12