हिंदी

Explain the working of IF-ELSE with the help of an example program.

Advertisements

प्रश्न

Explain the working of IF-ELSE with the help of an example program.

कोड लेखन
स्पष्ट कीजिए
Advertisements

उत्तर

The IF-ELSE statement in Java is a decision-making statement that executes one of two blocks of code depending on whether a given condition is true or false.

Working of IF-ELSE:

  1. The if statement checks the specified condition.
  2. If the condition is true, the if block is executed.
  3. If the condition is false, the else block is executed.
  4. After executing either block, the program continues with the next statement.

Example Program:

class IfElseExample 
{
    public static void main(String[] args) 
    {
        int num = 10;
        if (num % 2 == 0) 
        {
            System.out.println("Even Number");
        } 
        else 
        {
            System.out.println("Odd Number");
        }
    }
}

Output:

Even Number
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Statements and their Scope - EXERCISE [पृष्ठ १६३]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 7 Statements and their Scope
EXERCISE | Q 2. | पृष्ठ १६३
Advertisements
Share
Notifications



      Forgot password?
Use app×