-
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);
}
}
-
- 46
- 36
- 26
- 56
- 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