7. Reverse Integer

public class Main {


    public static void main(String[] args) {

        System.out.println(reverse(-123));

    }

    public static int reverse(int x) {

    long sum=0;
        while(x!=0){
        sum=sum*10+x%10;
        x=x/10;

    }

        if(sum <=Integer.MAX_VALUE && sum>=Integer.MIN_VALUE){
        return (int) sum;
    }else {
        return 0;
    }

}
}

 

posted @ 2020-06-06 16:48  lalalalatxx  阅读(105)  评论(0编辑  收藏  举报