Computer Science, asked by krishna00214, 11 months ago

State the output of the following code fragment :
(a) int k= 2, sum = 100;
switch (k++)
case 3: sum + = 10;
default : sum + = 20;
} System.out.println(sum + "\t” + k);​

Answers

Answered by anishasa
3

Answer:

K++ post-increment operator

The post increment operator k++ increments k but returns the previous value of k the switch statement gets the value 2

The default case can be used for performing a task when none of the cases is true.

so the default value is printed

sum = sum+20 ----> 120

Answer:

sum = 120

k = 3

Similar questions