Computer Science, asked by ruhi668, 11 months ago

JAVA PROGRAM TO INPUT A NUMBER AND CHECK WHETHER IT IS A MULTIPLE HARSHAD NUMBER OR NOT.(A NUM DIVISIBLE BY ITS SUM IS CALLED HARSHAD NUMBER)

Answers

Answered by Vyomsingh
6

Answer:Hey friend here is your answer.

class Harshad

{

void main (int n)

{

int m=n;

int sum=0;

for (int k=1;m>0;m/=10)

{

k=m%10;

sum=sum+k;

}

if (n%sum==0)

{

System.out.println ("Harshad");

}

}

}

Explanation:

Answered by anindyaadhikari13
28

Here is your answer.

class x

{

static void main(int n)

{

int s=0;

int a=n;

while(n!=0)

{

s+=n%10;

n/=10;

}

if(a%s==0)

System.out.println("Harshad Number.");

else

System.out.println("Not a Harshad Number.");

}

}

Similar questions