Computer Science, asked by shalinipareek1418, 9 months ago

Define if else - statement with syntax and programming examples​

Answers

Answered by aasthadani14
2

Answer:

it's a conditional statement.

example if you want to check whether num is even or odd like

syntax

if ( condition )

{

code

}

else

{

code

}

example

if ( num %2 == 0 )

{

print num is even

}

else

{

print num is odd

}

Answered by ichhadwivedi2004
1

Answer:

In if-else statement in Java, if the condition returns true then the statements inside the body of “if” are executed and the statements inside the body of “else” are skipped and if the condition returns false then the statements inside the body of “if” are skipped and the statements in “else” are executed.

SYNTAX

if(condition or test - expression)

{  body

}

else

{   body

}

EXAMPLE

class JavaTest

{

   public static void main(int number)

   {

       if(number % 2 == 0)

       {

       System.out.println("The Entered number is an Even Number");

       }

      else

      {

      System.out.println("The Entered number is an Odd Number");

      }

   }

}

In the above given example if the value entered is 6. Then, first the "if " condition checks, and here the condition becomes true and the "else" condition skipped and the value printed that "The Entered number is an Even Number".

On the other hand,  if the value entered is 9. Then, first the "if " condition checks, and here the condition becomes false. So, this condition is skipped  and the "else" condition evaluates. So, the value printed that "The Entered number is an Odd Number".

HOPE IT HELPS YOU...

Similar questions