/* */ Click to Join Live Class with Shankar sir Call 9798158723

If Statement in Java


If statement will executed in the code and check only if the condition is true.

Syntex :-

if"(condition)"
"{"
// you can enter a code here.
"}"

the statement is executed when the condition is true.

Q.) W.A.P to print number is greater than or less than between ?
// Java program to illustrate If statement

class IfDemo {
	public static void main(String args[])
	{
		int i = 10;

		if (i < 15)
			System.out.println("10 is less than 15");

		System.out.println("Outside if-block");
		// both statements will be printed
	}
}
Output
10 is less than 15 Outside if-block