-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarshad_Magic_Number.java
More file actions
38 lines (35 loc) · 1.01 KB
/
Copy pathHarshad_Magic_Number.java
File metadata and controls
38 lines (35 loc) · 1.01 KB
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
28
29
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class Harshad_Magic_Number {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int n=sc.nextInt();
int num=n,s=0,i,sum=0;
for(i=num;i>0;i=i/10){
int d=i%10;
s=s+d;
}
int s1=s;
if(n%s==0){
while (s1 > 0 || sum > 9)
{
if (s1 == 0)
{
s1 = sum;
sum = 0;
}
sum += s1 % 10;
s1 /= 10;
}
if(sum==1){
System.out.println("The numner is a Harshad Number");
}
else{
System.out.println("The numner is not a Harshad Number");
}
}
else{
System.out.println("The numner is not a Harshad Number");
}
}
}