UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Java program to study if statements

Java program for how if statement is using in java program.

by Krishna viswambharan


Posted on 20 Jul 2018 Category: Java Views: 15

Edited on 26 Jul 2018


Java program to study control statements

In this section, we will look closely at control statements. Here we will see the ‘if’ statement. Java  ‘if’ statement is syntactically identical to the if statements in C, C++ or C#.  Its syntax is shown here.

if(condition)

{

Statement;

}

Here, the condition is a Boolean expression. If the condition is true, then the statement is executed and if it is false, then the statement is bypassed.

Here is a simple java program that illustrates the if statement.  This program checks whether the given number is even or odd using Java control statement.

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

To compile : javac check.java

To Run : java check

OUTPUT 



Leave a Comment:


Advertisement