Char to Integer

题目:

Convert a char to an integer. You can assume the char is in ASCII code (See Definition, so the value of the char should be in 0~255.

分析:

强制类型转换方法,还有计算的方法...

解法1:

public class Solution {
    /**
     * @param character a character
     * @return an integer
     */
    public int charToInteger(char character) {
        // Write your code here
        int res = character - 'a' + 97;
        return res;
    }
}

解法2:

public class Solution {
    /**
     * @param character a character
     * @return an integer
     */
    public int charToInteger(char character) {
        return (int) character;
    }
}

results matching ""

    No results matching ""