我对粗体字感到困惑,这到底是什么意思,如果没有看到解决方案,怎么会有人弄清楚这一点?代码确实有效,但我不明白粗体字:
public int sumOfDigits(int n)
{
int sum = 0;
n = Math.abs(n); //removes the minus sign from a negative integer
while (n > 0)
***{
sum += n % 10; //???????????????????????????????????????xplo
n /= 10;
}***
return sum;
}
public void inputAndProcess()
{
int n = 0;
Input in = new Input();
while (true)
{
System.out.print("Type an integer: ");
if (in.hasNextInt())
{
n = in.nextInt();
break;
}
in.nextLine();
System.out.println("You did not type an integer, try again.");
}
System.out.print("The sum of the digits of " + n);
System.out.println(" is: " + sumOfDigits(n));
}
public static void main(String[] args)
{
new Example1_1().inputAndProcess();
}
我不能将选定的位加粗,但它是*中涵盖的代码的一部分,以及有关如何更好地处理这些过时代码的任何提示?