This is the 11th day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021
It’s singles Day again, and many bloggers are sending books to their fans. The fans of that one should not suffer, contacting the publishing house all night, and finally getting some free books and coupons for everyone. details
🌲 this article is included in the column “Java introduction exercise 100 cases” – try to learn the “Java basic grammar” after the consolidation and improvement and “LeetCode brush” before the small test knife.
Like it and see. Make it a habit. Wechat search [a coding] follow this programmer who is struggling in the Internet.
This article is included in the technical expert training, which contains my learning route, series of articles, interview question bank, self-study materials, e-books, etc. Welcome to star ⭐ ️
Topic describes
Difficulty: Easy
Computes the sum of the digits of the given integer 12345.
knowledge
- division
- Take over operations
Their thinking
The key to solving the problem is how to get the digits in each place.
Example: Get the ones and tens place of 34
int a=34;
// Divide by 3
int b=34/10;
// return the remainder 4
int c=34%10;
Copy the code
Code implementation
/** * Computes the sum of the digits of the given integer 12345. * /
public class question_07 {
public static void main(String args[]) {
int y = 12345;
int r = 0 ;
int sum = 0;
while(y! =0) {
r = y % 10;
sum += r;
y = y / 10;
}
System.out.println("y = "+ sum); }}Copy the code
The output
conclusion
Mastery of mod and divisor operations, great role.
The last
One foot is difficult to go, one hand is difficult to sing, a person’s power is limited after all, a person’s journey is doomed to be lonely. When you set a good plan, with full of blood ready to set out, must find a partner, and Tang’s monk to the West, the master and his disciples four people united as one to pass the ninety-eight difficult. So,
If you want to learn Java well
Want to go to company
Want to get high salary
Want to have a group of like-minded partners
Please join the technical exchange