LintCode 37. 反转一个3位整数

反转一个只有3位数的整数。

public class Solution {
    /**
     * @param number: A 3-digit number.
     * @return: Reversed number.
     */
    public int reverseInteger(int number) {
        // write your code here
        int a = 0, b = 0, c = 0, reverse = 0;
        a = number / 100;
        b = (number - a * 100) / 10;
        c = number - a * 100 - b * 10;
        if (c != 0) {
            reverse += c * 100;
        }
        if (b != 0) {
            reverse += b * 10;
        }
        if (a != 0) {
            reverse += a;
        }
        return reverse;
    }
}

你可能感兴趣的:(java开发,java,lintcode)