如何扭转一个数为整数,而不是作为一个字符串? [英] How to reverse a number as an integer and not as a string?
本文介绍了如何扭转一个数为整数,而不是作为一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个问题:怎样才能扭转数为整数,而不是作为一个字符串?任何人都可以请帮我找出答案。
I came across a question "How can one reverse a number as an integer and not as a string?" Could anyone please help me to find out the answer.
推荐答案
这应该做到这一点:
int n = 12345;
int left = n;
int rev = 0;
while(left>0)
{
r = left % 10;
rev = rev * 10 + r;
left = left / 10; //left = Math.floor(left / 10);
}
Console.WriteLine(rev);
这篇关于如何扭转一个数为整数,而不是作为一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文