A Java recursive program
•
Java
First of all, I searched some interview questions to do, including one: enter an integer and find the sum of each number in the integer?
Thinking: 1 How to or get each digit: if it is 1234, 1234% 10 = 4, get a digit; (1234 / 10)% 10 = 3 gets ten bits, (1234 / 100)% 10 = 2 gets a hundred bits, (1234 / 1000)% 10 = 1 gets a thousand bits.
2. Since a number is entered, the number of digits is uncertain. We can't use meaning judgment to remove 10, 100 or 1000,
At this time, my brain suggested that I use recursion, so I wrote the following code:
Operation result: 10. Done
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码