What is the reverse of Character.getNumericValue

亡梦爱人 提交于 2021-02-20 17:57:58

问题


    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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!