-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmith.java
More file actions
52 lines (52 loc) · 1.04 KB
/
Copy pathSmith.java
File metadata and controls
52 lines (52 loc) · 1.04 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
52
import java.util.Scanner;
class Smith
{
public static void main(String args[])
{
Smith obj=new Smith();
obj.read();
obj.check();
}
int n;
void read()
{
Scanner sc=new Scanner(System.in); System.out.println("Enter a number");
n=sc.nextInt();
}
int sum_of(int x)
{
int s=0,d;
while(x>0)
{
d=x%10;
x=x/10;
s=s+d;
}
return s;
}
void check()
{
int a=n;
int p=sum_of(a);
int f=2;
int sum=0;
while(a>1)
{
if(a%f==0)
{
sum=sum+sum_of(f);
a=a /f;
}
else
{
f++;
}
}
System.out.println("the sum of the digits "+sum);
System.out.println("the sum of the prime factors "+p);
if(p==sum)
System.out.println(n+" is a smith number");
else
System.out.println(n+" isn't a smith number");
}
}