-
Notifications
You must be signed in to change notification settings - Fork 0
/
whileloop.java
36 lines (32 loc) · 915 Bytes
/
whileloop.java
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
import java.util.*;
public class whileloop{
public static void main (String arg[]) {
Scanner sc = new Scanner(System.in);
// Write Your code here :
// int a = 1;
// while(a <= 100)
// {
// System.out.println("Hello Woorld" + a);
// a++; // ++a; a+=1; a = a+1;
// }
// Printing Table of 2:
// int a = 1;
// while(a<=10)
// {
// int b = 2*a;
// System.out.println("2 x " +a+" = " + b);
// a++;
// }
// Sum of n natural number :
System.out.print("Enter value of n : ");
int a = sc.nextInt();
int Sum = 0;
while(1 <= a)
{
Sum = Sum + a;
a = a+1;
}
System.out.println("The sum of n natural number is = "+ Sum);
sc.close();
}
}