FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
NumberPrograms/Smith_19.java at main · javaistic/NumberPrograms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
javaistic
/
NumberPrograms
Public
forked from
arghyaxcodes/NumberPrograms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
NumberPrograms
/
Smith_19.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (69 loc) · 1.71 KB
Breadcrumbs
NumberPrograms
/
Smith_19.java
Copy path
File metadata and controls
74 lines (69 loc) · 1.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
66
67
68
69
70
71
72
73
74
import
java
.
util
.*;
class
Smith_19
{
//function for finding sum of digits
int
sumDig
(
int
n
)
{
int
s
=
0
;
while
(
n
>
0
)
{
s
=
s
+
n
%
10
;
n
=
n
/
10
;
}
return
s
;
}
//function for generating prime factors and finding their sum
int
sumPrimeFact
(
int
n
)
{
int
i
=
2
,
sum
=
0
;
while
(
n
>
1
)
{
if
(
n
%
i
==
0
)
{
sum
=
sum
+
sumDig
(
i
);
//Here 'i' is the prime factor of 'n' and we are finding its sum
n
=
n
/
i
;
}
else
i
++;
}
return
sum
;
}
//function to check for composite number
boolean
isComposite
(
int
n
)
{
int
c
=
0
;
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
if
(
n
%
i
==
0
)
{
c
++;
}
}
if
(
c
>
2
)
return
true
;
else
return
false
;
}
public
static
void
main
(
String
args
[])
{
Smith_19
ob
=
new
Smith_19
();
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Enter a Number : "
);
int
n
=
sc
.
nextInt
();
if
(
ob
.
isComposite
(
n
) ==
false
)
{
System
.
out
.
println
(
"You have entered a non-Composite Number. Please enter a composite number"
);
}
else
{
int
a
=
ob
.
sumDig
(
n
);
// finding sum of digit
int
b
=
ob
.
sumPrimeFact
(
n
);
//finding sum of prime factors
System
.
out
.
println
(
"Sum of Digit = "
+
a
);
System
.
out
.
println
(
"Sum of Prime Factor = "
+
b
);
if
(
a
==
b
)
System
.
out
.
print
(
n
+
" is a Smith Number"
);
else
System
.
out
.
print
(
n
+
" is Not a Smith Number"
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL