Skip to content

Commit 5c5ed0f

Browse files
authored
Java Program - Sum of Natural Number
In this Program, we are adding Sum of First 10 Natural Number
1 parent beda62b commit 5c5ed0f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Test7_Natural_Number_sum.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.test.Basic_Java_Programs;
2+
3+
import java.util.Scanner;
4+
5+
public class Test7_Natural_Number_sum
6+
{
7+
public static void main(String[] args)
8+
{
9+
int n, sum = 0;
10+
11+
System.out.print("Enter Number :");
12+
13+
Scanner sc = new Scanner(System.in);
14+
15+
n = sc.nextInt();
16+
17+
for (int i = 1; i <= n; i++)
18+
{
19+
sum = sum + i;
20+
21+
}
22+
System.out.print("Addition "+ sum);
23+
}
24+
25+
}
26+
27+
28+
/* Output:
29+
30+
31+
Enter Number : 10
32+
Addition 55
33+
34+
35+
36+
*/

0 commit comments

Comments
 (0)