If a number is completely divisible by sum of the digits of the number, it is known as Niven number.
import java.util.*;
class Ab
{
int n,m;
Ab(int x)
{
n=x;
}
public void show()
{
m= sumOfDigits (n);
if(n%m==0)
System.out.println(“Niven Number:”);
else
System.out.println(“Not Niven Number:”);
}
private int sumOfDigits(int n)
{
int c=0,i;
for(i=n;i>0;i=i/10)
{
c=c+i%10;
}
return c;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the number:");
n=sc.nextInt();
Ab obj=new Ab(n);
obj.show();
}
}
No comments:
Post a Comment