-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarshad.java
More file actions
26 lines (26 loc) · 845 Bytes
/
Copy pathHarshad.java
File metadata and controls
26 lines (26 loc) · 845 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
// Write a method to determine whether a number is a Harshad number or not
import java.util.Scanner;
public class Harshad {
public static void Harshad(int number){
int store = 0;
String strNum = String.valueOf(number);
for(int i = 0; i < strNum.length(); i++){
char ch = String.valueOf(number).charAt(i);
int digit = ch - '0';
store += digit;
}
System.out.println(store);
if(number % store == 0){
System.out.println("Harshad Number");
}
else{
System.out.println("Not Harshad");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number to check for Harshid Number: ");
int number = sc.nextInt();
Harshad(number);
}
}