Lesson 9 of 34

switch: பல மதிப்புகளில் ஒன்றைத் தேர்வு செய்தல்switch: Choosing Between Many Values

8 min 30 XP

ஒரு variable-ன் மதிப்பைப் பொறுத்து பல வழிகளில் ஒன்றைத் தேர்வு செய்ய switch பயன்படுகிறது. ஒவ்வொரு case-ன் முடிவிலும் break வேண்டும், இல்லையெனில் அடுத்த case-ம் இயங்கும். எதுவும் பொருந்தவில்லை என்றால் default இயங்கும்.

switch picks one of many paths based on a value. Each case needs a break at the end, or the next case runs too (fall-through). default runs when nothing matches.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

switch, String மற்றும் char மதிப்புகளுடனும் வேலை செய்யும். கீழே ஒரு சிறிய calculator.

switch also works with String and char values. Here is a tiny calculator.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Challenge

+30 XP

இரண்டு எண்கள் மற்றும் ஒரு operator (+ - * /) படித்து விடையை print செய்யுங்கள். வேறு operator வந்தால் "Invalid" என்று print செய்யுங்கள். Input: 8 * 5 → Output: 40

Read two numbers and an operator (+ - * /) and print the result. For any other operator print "Invalid". Input: 8 * 5 → Output: 40

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.