header-logo.png GKINDEX

Java if else block

Java if else is a control statement which is used control some part of the application execution.

Java If else example

In the above example, if we see in the if statement we are checking whether 'i' is greater than the value of 'j'. As we know 'i' and j variables are initialized to 10 and 5 respectively.

So, i value 10 is always greater than the j value 5 hence the if block is going to be executed and else block will not be executed.

Lets see another example in reverse direction.

If we see in the above example, j value is initialized to 10 and i value is initialized to 5. Hence i value is not greater than the j value, so if block is not going to be executed and else block gets executed.

Java if else is a control statement which is used control some part of the application execution.
  • Share