Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
if statement in java - Testingpool

if statement in java

In the previous post, we have seen the working of for each loop in java. In this post, we will look at if statement in java.

In every programming language, at some point we need to put few conditions check or verification. if statement is used to to verify the conditions, that’s why it is called conditional statement. After condition check, it evaluates boolean value like true or false. If true, it enters the if statement block and performs necessary tasks, else exit the conditional statement.

Syntax of if statement:

if(Boolean_expression)
{
   //Statements will be executed if the Boolean expression is true
}

Example of if statement:

public class ExampleIfStatement {
	public static void main(String[] args) {
		int a = 100;
		if(a<200){
			System.out.println("Value of a : "+a);
		}		
	}
}
Output: Value of a : 100

if ..else statement:

We can perform different tasks on the basis of conditions evaluation like true or false. For that we can associate else statement with if statement. 

Example of if ..else:

public class ExampleIfStatement {
	public static void main(String[] args) {
		int a = 100;
		if(a<50){
			System.out.println("Value of a is less that actual value: "+a);
		}else{
			System.out.println("Value of a is not less that actual value: "+a);
		}
	}
}
Output: Value of a is not less that actual value: 100
Questions/Suggestions
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

2 Responses

  1. August 10, 2015

    […] the previous post, we have seen if else statement. In this post, we will learn about elseif […]

  2. August 10, 2015

    […] In the previous post, we have seen the conditional statements. […]