2 回答
TA贡献1883条经验 获得超3个赞
您正在更改循环内的 num2,请尝试使用以下内容:
num1 = 57;
num2 = 34;
int tempNum2 = num2;
while ( num1 > 0 ) {
digit1 = num1 % 10;
num1 = num1 / 10;
System.out.println("num1 digit: " + digit1);
while (tempNum2 > 0 ) {
digit2 = tempNum2 % 10;
System.out.println("num2 digit: " + digit2);
tempNum2 = tempNum2 / 10;
}
tempNum2 = num2;
}
TA贡献2036条经验 获得超8个赞
您需要在 num1 > 0 的 while 循环中重新声明 num2 整数,才能再次运行 num2 > 0;
int num1 = 57;
int num2 = 34;
while ( num1 > 0 ) {
digit1 = num1 % 10;
num1 = num1 / 10;
System.out.println("num1 digit: " + digit1);
while (num2 > 0 ) {
digit2 = num2 % 10;
System.out.println("num2 digit: " + digit2);
num2 = num2 / 10;
}
//Add here
num2 = 34;
}
添加回答
举报