1. 程式人生 > >輸入一個數,將順序逆轉,例如輸入123,輸出321

輸入一個數,將順序逆轉,例如輸入123,輸出321

實現程式碼如下:
package test;

public class Test5 {
	public static int reverse(int x) {
		long result = 0;
		while(x!=0){
			int n = x%10;
			result = result*10+n;
			x=x/10;
		}
		if( result > Integer.MAX_VALUE || result < Integer.MIN_VALUE)
            return 0;
		return (int)result;
	}
	public static void main(String[] args) {
		int x=153423646;
		int y = Test5.reverse(x);
		System.out.println(y);
	}
			
}
如果你有更好的方法,請加QQ群691761026一起交流