Skip to content

Commit b00eeb2

Browse files
authored
Update
1 parent ee36e02 commit b00eeb2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rec.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.Scanner;
2+
public class Sum
3+
{
4+
public static void main(String[] args)
5+
{
6+
Scanner sc=new Scanner(System.in);
7+
int a=sc.nextInt();
8+
int res=sum(a);
9+
System.out.println(res);
10+
}
11+
public static int sum(int s)
12+
{
13+
if(s>0)
14+
{
15+
return s+sum(s-1);
16+
}
17+
else
18+
{
19+
return 0;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)