MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / main

Method main

Lecture 07_Loops/src/WhileLoop.java:5–20  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

3//print 1 to n
4public class WhileLoop {
5 public static void main(String[] args) {
6 Scanner sc = new Scanner(System.in);
7 int n = sc.nextInt();
8 int sum = 0;
9
10 int num = 1;
11
12 while (num <= n){
13// System.out.println(num);
14 sum = sum + num;
15 num++; // increment operator ++ , num = num + 1
16 }
17
18 System.out.println(sum);
19
20 }
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected