< Prev
Next >


If Statement





In Java, an If statement is used when we want to test a condition, which is evaluated for a boolean value - true or false.





Java - if statement example


//Java - if statement program
  
public class A
{
public static void main(String... ar)
{
if(100>5)
	System.out.println("100 is greater than 50");

	
if(50<100)
{
	System.out.println("50 is less than 100");
	System.out.println("Second statement to execute");
}


if(2>4)
{
System.out.println("2 is greater than 4");
}


System.out.println("Statement outside If Statement"); //not associated with any if block


}
}


Output is -


100 is greater than 50
50 is less than 100
Second statement to execute
Statement outside If Statement



Program Analysis

Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
Python

Ad2