-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram17.java
More file actions
27 lines (23 loc) · 739 Bytes
/
Program17.java
File metadata and controls
27 lines (23 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Program 17
// Day 4 - Week 1
//Find wether the given number is Harsad number
// Harshad Number: If the number is divisible by sum of digit of the number
import java.util.Scanner;
public class Program17 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();
int sum = 0;
int temp = number;
while (temp > 0) {
sum += temp % 10;
temp /= 10;
}
if (number % sum == 0) {
System.out.println(number + " is a Harshad number.");
} else {
System.out.println(number + " is not a Harshad number.");
}
}
}