Program to Check If a Number is Harshad number or not.
Harshad Number CodeWithVed
Steps:-
Program:-
// Java Program to Check If a Number is Harshad number or not.
class Harshad
{
public static void main(String[] args)
{
System.out.println("Enter the value");
int n1=new java.util.Scanner(System.in).nextInt();
int num, rem=0, sum=0;
num=n1;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
if(n1%sum==0)
{
System.out.println(n1 + " is a Harshad number ");
}
else
{
System.out.println(n1 + " is a not Harshad number");
}
}
}
No comments:
Post a Comment