+ 1

Solution needed

int x=4; do{ switch(x){ case 4: case 5: break; default: System.out.print(x); }} while(++x<8); in mcq challenge part it shows 67 as answere. but how? any explanation?

3rd Nov 2022, 12:04 PM
Mustakim Rahman
Mustakim Rahman - avatar
1 Odpowiedź
+ 4
It has switch block inside a do while loop. For x = 4 and 5 , nothing outputs because case 4, 5 have no statement except break. It had fall through. And for x = 6 , 7 : prints 6 , 7 by default case 8<8 false so loop gets terminated. when a case is matched and the case has no break then falls to next case irrespective of matching.
3rd Nov 2022, 12:13 PM
Jayakrishna 🇮🇳