Program To Print Niven Number JAVA


Write a Program to print whether the inputted number is Niven or not.




[A number is said to be Niven which is divisible by the sum of its digits.
Example: 126
Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.]


import java.util.*;
class niven
{
    public static void main(String args[])
    {
     Scanner sc = new Scanner (System.in);
     int n = sc.nextInt();
     int temp =n,sum =0;
     while (n!=0)
     {
         sum = sum + (n%10);
         n=n/10;
     }
     System.out.println(sum);
     if(temp % sum == 0)
     {
     System.out.println("yes it is niven number");
     }
     else
     {
     System.out.println("No it is not niven");
    }
}
}

     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com