#Digital Roots#写个while循环就行
Digital Roots
https://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414
//Java写法
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
while (n > 9) {
int sum = 0;
int temp = n;
while (temp > 0) {
sum += temp % 10;
temp /= 10;
}
n = sum;
}
System.out.println(n);
}
}
}
#Python写法
while True:
try:
n = int(input())
while n > 9:
n = sum(map(int, str(n)))
print(n)
except:
break


查看10道真题和解析