Tuesday , December 6 2016
Home / JAVA / ICSE Class 10 / Harshad Number Program in Java (Niven Numbers)

Harshad Number Program in Java (Niven Numbers)

Java Program to check for Harshad Number:  What is a Harshad Number? Harshad Number also called Niven Number is a number that is divisible by the sum of its digits.

Example:

  • Number 200 is a Harshad Number because sum of digits 2 and 0 and 0 is 2(2+0+0) and 200 is divisible by 2.
  • Number 171 is a Harshad Number because sum of digits 1 and 7 and 1 is 9(1+7+1) and 171 is divisible by 9.
  • Number 36 is a Harshad Number because the sum of the digits 3 and 6 is 9(3+6) and 36 is divisible by 9.Java Program Harshad Numbers

Some examples of Harshad Number Series are:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100, 102, 108, 110, 111, 112…

  • Output:

    Please enter a positive integer (>=1): 18
    18 is a Harshad Number.

    Please enter a positive integer (>=1): 0
    Sorry, the integer must be greater than or equal to 1.
    Please enter a positive integer (>=1): 20
    20 is not a harshad number.

    Please enter a positive integer (>=1): 201
    201 is a Harshad Number.

  • Output:

    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100, 102, 108, 110, 111, 112, 114, 117, 120, 126, 132, 133, 135, 140, 144, 150, 152, 153, 156, 162, 171, 180, 190, 192, 195, 198, 200.

 

 

Also See:   What is Java and why is java needed?

Check Also

Program for Matrix Multiplication in JAVA

Matrix Multiplication:– Here is given a Java Program for Matrix Multiplication also call matrix product. In ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.