forked from azure2103/program-wiz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmith.java
More file actions
51 lines (51 loc) · 1.22 KB
/
smith.java
File metadata and controls
51 lines (51 loc) · 1.22 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
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.*;
public class Smith
{
public static void main()
{
Scanner sc=new Scanner (System.in);
int n;
System.out.println("Enter a number");
n=sc.nextInt();
int num=n;
int sum=0;
int y=1;
int i;
while (n!=0)
{
int d=n%10;
sum=sum+d;//sum of the digits
n=n/10;
}
int sum1=0;
for (i=2;i<=num;i++)
{
y=num%i;
while (y==0)
{
if (y == 0)
{
n=i;
int sum2 = 0;
while (n!=0)
{
int f=n%10;
sum2=sum2+f;//sum of the digits
n=n/10;
}
sum1 = sum1 + sum2;
}
num=num/i;
y = num%i;
}
}
if (sum1==sum)
{
System.out.println("Smith number");
}
else
{
System.out.println("Not a smith number");
}
}
}