Home » JAVA Programming » Loop Control » Question
  1. What is the output of this program?

    public class comma_operator
    {
    public static void main(String args[])
    {
    int sum = 0;
    for (int k = 0, L = 0; k < 10 & L < 10; ++k, L = k + 1)
    sum += k;
    System.out.println(sum);
    }
    }
    1. 46
    2. 36
    3. 26
    4. 56
    5. None of these
Correct Option: B

Using comma operator , we can include more than one statement in the initialization and iteration portion of the for loop. Therefore both ++k and L = k + 1 is executed
output: 36



Your comments will be displayed only after manual approval.