FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProgrammingHacktoberFest/Recursion/SumOfNaturalNo.java at main · basukinath/JavaProgrammingHacktoberFest · GitHub
basukinath
/
JavaProgrammingHacktoberFest
Public
forked from
karterhhgg/JavaProgramming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProgrammingHacktoberFest
/
Recursion
/
SumOfNaturalNo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (21 loc) · 579 Bytes
Breadcrumbs
JavaProgrammingHacktoberFest
/
Recursion
/
SumOfNaturalNo.java
Copy path
File metadata and controls
22 lines (21 loc) · 579 Bytes
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
// Print the sum of first n natural numbers.
package
Recursion
;
import
java
.
util
.*;
public
class
SumOfNaturalNo
{
public
static
void
printSum
(
int
i
,
int
n
,
int
sum
) {
if
(
i
>
n
){
System
.
out
.
println
(
sum
);
return
;
}
sum
=
sum
+
i
;
// sum+=n;
printSum
(
i
+
1
,
n
,
sum
);
}
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
i
=
1
;
System
.
out
.
print
(
"Enter the value: "
);
int
num
=
sc
.
nextInt
();
int
sum
=
0
;
printSum
(
i
,
num
,
sum
);
}
}
Back
|
FazBrowse Home
|
New Git URL