问题
int x = Character.getNumericValue('A');
System.out.println(" the value of x is: " + x); // prints 10
I am looking for a method that takes in somemethod(10)
and returns 'A'. Does such a method exist in java ?
回答1:
As stated by Anubian Noob and Jeroen Vannevel, Character.GetNumericValue('A') = 10
, Character.GetNumericValue('a') = 10
and `Character.forDigit(10, 36) ='a'.
So IMHO, what is closest of what you ask would be
Character fromNumericValue(int x) {
if ((x < 0) || (x > 35)) {
throw new IllegalArgumentException();
}
return Character.toUpperCase(Character.forDigit(x, 36));
}
It works for numbers between 0 and 9, returning chars '0' to '9', and for numbers between 10 and 35 returning letters 'A' to 'Z'. But I cannot imagine how you will use it.
来源:https://stackoverflow.com/questions/24101052/what-is-the-reverse-of-character-getnumericvalue