Sum of Digit in Java

 SUM OF DIGIT IN JAVA. 


*********************************

import java.util.Scanner;
public class Sum_of_Digit
{
   public static void main (String args[])
   {
      Scanner sc=new Scanner(System.in);
       int num, d, sum=0;
      System.out.println("ENTER A NUMBER");
      num=sc.nextInt();
   
      while(num!=0)
       {
           d=num%10;
           sum=sum+d;
           num=num/10;
       }
     
     System.out.println("Sum of Digits = "+sum); 
   }
}

*******************************
By- BLUEJ HUB 





Post a Comment

0 Comments