-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmith.java
More file actions
66 lines (60 loc) · 1.29 KB
/
Smith.java
File metadata and controls
66 lines (60 loc) · 1.29 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
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
class Smith
{
int add(int x)
{
int sum=0,rem=0;
while(x>0)
{
rem=x%10;
sum=sum+rem;
x=x/10;
}
return sum;
}
boolean prime(int x)
{
int ctr=0;boolean flag=false;
for(int i=1;i<=x;i++)
{
if(x%i==0)
ctr++;
}
if(ctr==2)
flag=true;
else
flag=false;
return flag;
}
void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter the number to be checked:");
int x=sc.nextInt();
int sum=add(x);
int sum1=0;
boolean check=false;
for(int i=2;i<=x;i++)
{
if(x%i==0)
{
x=x/i;
check=prime(i);
if(check==true&&i>10)
{
int add1=add(i);
sum1=sum1+add1;
}
else if(check==true)
{
sum1=sum1+i;
}
i=2;
}
}
if(sum1==sum)
System.out.println("It is a smith number.");
else
System.out.println("It is not a smith number.Thank you!");
}
}