int value = 456702;
do
{
digit = value % 10;
value = value / 10;
System.out.println(digit); //I just want to get...2,0,7,6,5,4
} while (digit > 0);
我试过了,但效果不佳,因为当它得到数字 0 时,它就退出循环。
我只想查找和检索给定数字的数字。
例如256387,我需要这个数独立涉及的数字,即7、8、3、6、5、2,我试过了。我的代码适用于没有零的数字。我怎么知道我到达了最后一位数字(例如从左到右)?
最佳答案
将 while (digit > 0)
中的条件替换为 (value > 0)
关于java - 找出给定数字的所有数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26252024/