This is a BlueJ Program of Harshad Number checking.
Any number which is completely divisible by the sum of the digits of the number is known Harshad Number. Example of Harshad Number is 200 as it is completely divisible by 2 (2+0+0=2)
import java.util.*;
public class Duck
{
Scanner sc=new Scanner(System.in);
public void showHarshad()
{
System.out.print("\nEnter the number:");
int n=sc.nextInt();
int sum=0;
for(int i=n;i >0;i=i/10)
{
sum=sum+i%10;
}
if(n%sum==0)
System.out.print("\nEntered number is a Harshad number.");
else
System.out.print("\nEntered number is not a Harshad number.");
}
public static void main(String args[])
{
Duck obj=new Duck();
obj.showHarshad();
}
}
Related Post: BlueJ Programs on Number
No comments:
Post a Comment