Wednesday, August 22, 2018

How to find sum of all digits of a number in java?



package com.altafjava.sad.test;

public class SumAllDigit {
public static void main(String[] args) {
int num=9526;
System.out.println("Original number = "+num);
int sum=0;
while(num!=0){
int remainder=num%10;
sum=sum+remainder;
num=num/10;
}

System.out.println("Sum = "+sum);
}
}






How to find sum of all digits of a number in java?
How to find sum of all digits of a number in java?




Share this

0 Comment to "How to find sum of all digits of a number in java?"

Post a Comment