Posts

Showing posts with the label switch case in java

Switch Case Statement in java जावा में स्विच केस स्टेटमेंट

The switch statement in Java allows the value of an expression or variable to be compared with multiple constant values. It is a control structure that works only with integer , character , enum , or string types. Each case in a switch is associated with a constant value followed by a colon ( : ), and if the expression matches a case value, the corresponding block is executed. To prevent the fall-through behavior, the break; statement is used at the end of each case. A special default case (which is optional) runs when no other cases match. The switch statement is often used as a cleaner alternative to nested if...else statements. Java में switch स्टेटमेंट का प्रयोग एक वैरिएबल या एक्सप्रेशन की वैल्यू को कई अलग-अलग स्थायी (constant) वैल्यूज से तुलना करने के लिए किया जाता है। यह कंट्रोल स्ट्रक्चर केवल इन्टिजर , कैरेक्टर , एनम , या स्ट्रिंग एक्सप्रेशन पर कार्य करता है। प्रत्येक case के साथ एक निश्चित वैल्यू और : का उपयोग होता है। यदि कोई केस वैल्यू एक्सप्रेशन से मेल खाती है...