public class StringRevers {
/**
*int 类型反转
*test:1 1
*test:-1 -1
*test:123 321
*test:-123 -321
*test:-123456789 -987654321
*test:123456789 987654321
*/
public static void main(String[] args) {
int a=-123456789;
System.out.println(StringRevers.reverse(a));
}
public static int reverse(int a){
int num=a;
a=Math.abs(a);
int rs = 0;
while(a>0){
rs*=10;
rs+=a%10;
a/=10;
}
return(num>0)?rs:-rs;
}
最后
以上就是如意枕头最近收集整理的关于整型反转 如-123反转成-321的全部内容,更多相关整型反转内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复