+ 1
sum digits
how do i write a program that gets a positive integer from the user and then sums the digits, using remainder and division math operators. (e.g the user types in 15, the program should add 1+5 and output the result)
8 Respostas
+ 5
Bobby Dike are you referring to something like this
public class Program
{
public static void main(String[] args) {
int sum = 0;
for(int i = 1;i < 10; i++){
System.out.println(sum);
sum += i;
}
}
}
+ 2
Bobby Dike
n=0;
while n! = 0
{
r=n%10;
System.out.println(r) ;
n=n/10;
}
In the above algorithm I am printing out the numbers but you can sum up the numbers (assuming you know how to do it)
+ 1
Bobby Dike good luck figuring it out your own i guess or if you need help copy paste the code .
Tag me using @ followed by my name if you copy paste the code or share the link.
0
pls can you write a code of your example.
i don't quite understand
0
is it sum+=n?
0
Bobby Dike sum+=r
0
im having an error