Niven Number

 //Any positive integer which is divisible by the sum of its digits is a Harshad Number or Niven Number

//152 is a niven number

import java.util.*;

class niven

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        int num,r,sum=0,temp;

        System.out.println("Enter a number:");

        num=sc.nextInt();

        temp=num;

        while(temp>0)

        {

            r=temp%10;

            sum=sum+r;

            temp=temp/10;

        }

        if(num%sum==0)

        System.out.println(num+" is a Niven number");

        else

        System.out.println(num+" is not a Niven number");

    }

}

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...