Happiness is more than pleasure without pain

你只有非常努力,才能看起来毫不费力

导航

Reverse Integer

import java.util.*;
public class Solution {
    public static int reverse(int x) {
    int a=x,tmp=0,i;
    int []b=new int[32];
    for(i=0;i<32;i++){
    if(a!=0){
    b[i]=a%10;
    a=a/10;
    }
    else
    break;
    }
    int in=1;
        for(int j=i-1;j>=0;j--){
        tmp+=b[j]*in;
        in*=10;
        }
    return tmp; 
//     int res = 0;
// while (x != 0) {
// res = res * 10 + x % 10;
// x = x / 10;
// }
// return res;


    }
    public static void main(String[] args){
    Scanner cin=new Scanner(System.in);
    while(cin.hasNextInt()){    
    int n=cin.nextInt();
    System.out.println(Solution.reverse(n));
    }
    }
}


posted on 2014-09-20 10:04  believer  阅读(109)  评论(0编辑  收藏  举报