Menu
Topics Index
...
`

After adding Sum is2268


If you need explanation Read this topic

If you need Answer Take test on this topic

After adding Sum is2268
What will be the output of the following program?
public class AddingInLoop {
    public static void main(String[] args) {
        int sum = 10;
        int i = 0;
        while (i <= 5) {
            sum += i;
            i++;
        }
        System.out.println("Sum = " + sum);
    }
}

A. Sum = 10
B. Sum = 20
C. Sum = 25
D. Compilation Error
E. Runtime Error
Topic: for Loop Example Program In Java - Sum Of Numbers

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

c

Posted by Indrasena Reddy    2014-01-20 03:52:02


Ans C
10+0+1+2+3+4+5=25

Posted by Jayachandra Gupta    2014-01-20 03:52:22


c

Posted by Indrasena Reddy    2014-01-20 03:52:25


C

Posted by Ashutosh Mishra    2014-01-20 03:59:29


The loop will run for 6 times i=0 to i=5
Thus, sum = 10=0+1+2+3+4+5=25

Posted by Sowmya Vepa    2014-01-20 04:55:58


25

Posted by Akash Kolariya    2014-01-20 06:09:00


c is ans  because 6 times loop first 0 will be add and next 1 ..........5=25

Posted by Prudviraj Regumani    2014-01-20 06:50:38


Congratulations Jayachandra Gupta. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-21 03:43:57


Jayachandra has a postpaid network ,he cant recharge ! :P

Posted by Ashutosh Mishra    2014-01-21 03:51:28


LoL :) have almost 10 numbers all with postpaid....everytime I win am donating it behalf of MeritCampus.....this time u want to take it Ashutosh Mishra :)

Posted by Jayachandra Gupta    2014-01-21 03:53:28


hahaha :D yalet me try how to utlize the recharge claim  ;) inbox me :D

Posted by Ashutosh Mishra    2014-01-21 04:04:04


sure....chk ur inbox... :)

Posted by Jayachandra Gupta    2014-01-21 04:04:41


got the recharge?? :)

Posted by Jayachandra Gupta    2014-01-21 04:17:31


Ya ! Thanks ! JC is such a big heart :) now whole month I can talk for free :)

Posted by Ashutosh Mishra    2014-01-21 04:21:14


LoL....!

Posted by Jayachandra Gupta    2014-01-21 04:24:53


© meritcampus 2019

All Rights Reserved.

Open In App