Advertisement
Hiteshw11

Sum Of All digits in a Number

Jul 14th, 2020
1,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class sumdigit {
  4.  
  5.     public static void main(String args[])
  6.     {
  7.         Scanner src=new Scanner(System.in);
  8.         System.out.println("Enter the number");
  9.         int a=src.nextInt();
  10.         int n,sum=0;
  11.         while (a>0)
  12.         {
  13.         n=a%10;
  14.         sum=sum+n;
  15.         a=a/10;
  16.         }
  17.         System.out.println("The sum is "+sum);
  18.     }
  19.    
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement