輸入一個數,將順序逆轉,例如輸入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一起交流
發佈了29 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章