Skip to main content

Posts

Showing posts with the label 14. Write a Java program to calculate sum of digits of a number.

ads1

14.Write a Java program to calculate sum of digits of a number.

14. Write a Java program to calculate sum of digits of a number. Static :-   { public static void main(String args[]) { int n=12,sum=0; while(n!=0) { sum += n%10; n=n/10; } System.out.println("Sum is :- "+sum); } } Output :-  

ads2