package com.thealgorithms.maths;
import java.util.Scanner;
public class HarshadNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
long a = sc.nextLong();
checkHarshadNumber(a);
}
public static void checkHarshadNumber(long a) {
long b = a;
int sum = 0;
int[] each = new int[Long.toString(a).length()];
int c = 0;
while (b > 0) {
sum += b % 10;
each[c] = (int) (b % 10);
b /= 10;
c++;
}
if (a % sum == 0) {
System.out.println(a + " is a Harshad Number");
System.out.println("\nExplaination :");
for (int i = each.length - 1; i >= 0; i--) {
System.out.print(each[i] + " ");
if (i != 0) {
System.out.print("+ ");
}
}
System.out.println("= " + sum);
System.out.println(sum + " × " + (a / sum) + " = " + a);
} else {
System.out.println(a + " is not a Harshad Number");
}
}
}