Lesson 9 of 34

switch: പല values-ൽ നിന്ന് തിരഞ്ഞെടുക്കൽ

8 min 30 XP

switch ഒരു value-യെ അടിസ്ഥാനമാക്കി പല വഴികളിൽ ഒന്ന് തിരഞ്ഞെടുക്കുന്നു. ഓരോ case-ന്റെ അവസാനവും break വേണം, അല്ലെങ്കിൽ അടുത്ത case-ഉം പ്രവർത്തിക്കും (fall-through). ഒന്നും പൊരുത്തപ്പെടാത്തപ്പോൾ default പ്രവർത്തിക്കുന്നു.

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 values-നൊപ്പവും പ്രവർത്തിക്കുന്നു. ഇതാ ഒരു ചെറിയ 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

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