星空网 > 软件开发 > Java

7. Reverse Integer java

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

 

代码如下:

public class Solution {
    public int reverse(int n) {
        long sum=0;
        int flag=1;
       
        if(n<0)
        {
            flag=-1;
            n=n*(-1);
        }
        try{
        String s=Integer.toString(n);
        s=new StringBuffer(s).reverse().toString();
        sum=Integer.valueOf(s)*flag;
        }catch(NumberFormatException e)
        {return 0;}
 
    return (int)sum;
    }
}




原标题:7. Reverse Integer java

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

tiktok高清下载:https://www.goluckyvip.com/tag/82479.html
清库存:https://www.goluckyvip.com/tag/8248.html
tiktok国内下载:https://www.goluckyvip.com/tag/82480.html
tiktok的前身:https://www.goluckyvip.com/tag/82481.html
越南tiktok带货:https://www.goluckyvip.com/tag/82482.html
tiktok白名单账号:https://www.goluckyvip.com/tag/82483.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
西藏旅游攻略自驾游需要多少天 去西藏旅游自驾游要多久时间:https://www.vstour.cn/a/363195.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流