Computer Science, asked by kumarisravani442, 6 months ago

write a program in java to accept a number and check whether the number is Niven/harshad number or not​

Answers

Answered by negiabhishek236
1

Answer:

Java program to check for Harshad Number (Niven Number)

•The number 18 is a Harshad number in base 10, because the sum of the digits 1 and 8 is 9 (1 + 8 = 9), and 18 is divisible by 9 (since 18 % 9 = 0)

•The number 1729 is a Harshad number in base 10, because the sum of the digits 1 ,7, 2 and 9 is 19 (1 + 7 + 2 + 9 = 19), and 1729 is divisible by 19 (1729 = 19 * 91)

Explanation:

this answer is absolutely correct

Answered by CopyThat
5

Program: {JAVA}

import java.util.*;

public class Brainly

{

static void main()

{

Scanner sc=new Scanner(System.in);

int d,s=0,n,t;

System.out.println("Enter an integer:");

n=sc.nextInt();

t=n;

while(t!=0)

{

d=t%10;

s=s+d;

t=t/10;

}

if(n%s==0)

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

else

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

}

}

Similar questions