If you solve your problem, please adopt it. If you have any questions, please ask. Thank you!
Parcel? com . zyx . cn . Baidu _ test;
Import? Java . util . scanner;
/**
*? Write a function sum(i), sum the bits of the input shaping parameter i(i≥0), and return the sum result.
*? Test this function in the main () function, input the integer n(n∈) from the keyboard,
*? Then input n non-negative integers, and call the sum function for each non-negative integer to find the sum of digits.
*? Output the results to the screen.
*? @ Author? yltd
*/
Public? Class? SumShow? {
Public? Static electricity Invalid? main(String[]? args)? {
Scanner? sc=? New? Scanner (system. in);
System.out.println ("Please enter a number greater than or equal to 0 and less than or equal to 20");
int? Me? = sc . nextint();
Sum (1);
System.out.println ("Please enter a non-negative integer");
int? Two? = sc . nextint();
Sum (2);
}
Public? Static electricity int? sum(int? i){
int? sum? =0;
For what? (int? j? =? 0; ? j? & lt=? Me; ? j++)? {
sum+= j;
}
system . out . println(sum);
Return? Sum;
}
} Please enter a number greater than or equal to 0 and less than or equal to 20.
10
55
Please enter a non-negative integer
20
2 10