Menu
Coddy logo textTech

Simple if Statement

Lesson 2 of 11 in Coddy's Control Statements in Java course.

This is the very first statement you are learning, so as the name suggests, "Simple if" means you will run/execute a particular code only if the condition is true.

Example: You will eat ice-cream only if you are not suffering from a cold.

If the condition is false, the control jumps to the next line of code after the if statement, i.e., the next part of the program will run sequentially.

Syntax (the way to write the statement):

if(condition)​
{​
    //code​
}​
challenge icon

Challenge

Easy

Implement a method isEven(int) which takes an int as Input, If the number is even return 1 otherwise return 0.

Try it yourself

class IsEven {
    public static int isEven(int a1) {
        // Write code here
    }
}

All lessons in Control Statements in Java

1What are Control Statements?

Introduction