In my previous post, nosotros lead maintain seen unlike information types inward coffee software evolution language. It is really of import to larn basic coffee tutorials If you lot wants to larn selenium webdriver alongside Java. Because If you lot exercise non lead maintain noesis of basic java software evolution hence you lot tin non exercise unmarried logical webdriver evidence case. And also you lot tin non operate past times any company interview for webdriver software testing tool. So proceed your eyes on these tutorials in addition to I volition accept you lot from basic to advanced coffee tutorials pace past times step. In this post, Let me tell you lot the usage of If else conditional statements inward java.
if, if else in addition to nested if else statements are useful to accept the determination based on conditional match.When you lot wants to execute or hence purpose of code if status returns truthful hence you lot require to utilization this form of conditional statements.
Simple If Statement
Part of code volition last executed alone if specified status returns true. If status volition provide faux hence that code volition last non executed.
Example :
if (i<j) System.out.println("Value Of i("+i+") Is Smaller Than Value Of j("+j+")." );
In inward a higher house given example, message volition last printed alone in addition to alone if value of variable i is less than value of variable j.
If else Statement
If status returns truthful hence purpose of if block volition last executed. If status returns faux hence purpose of else block volition last executed.
Example :
if (i>=j) { System.out.println("Value Of i("+i+") Is Greater Than Or Equals To Value Of j("+j+")." ); }else { System.out.println("Value Of i("+i+") Is Smaller Than Value Of j("+j+")." ); }
In inward a higher house given example, if block's message volition last printed if value of variable i is greater than or equals to value of variable j. else block volition last executed if value of variable i is less than value of variable j.
Nested If Else Statements
You tin utilization nested if else disputation when you lot wants to banking venture check multiple weather in addition to accept determination based on it.
Example :
if (k<i) { System.out.println("Value Of k("+k+") Is Less Than Value Of i("+i+")" ); }else if (k>=i && k<=j) { System.out.println("Value Of k("+k+") Is In Between Value Of i("+i+") And Value Of Value Of j("+j+")" ); }else { System.out.println("Value Of k("+k+") Is Greater Than Value Of j("+j+")" ); }
In inward a higher house given example, get-go (if) block volition last executed if value of variable k is less than the value of variable i. Second (else if) block volition last executed if value of variable k is greater than or equals to value of variable i in addition to less than or equals to value of variable j. Third (else) block volition last executed if value of variable k is greater than value of value of variable j. You tin brand a chain of if else disputation if you lot wants to banking venture check to a greater extent than conditions.
This way, You tin utilization whatever of inward a higher house conditional disputation based on your requirement. Run bellow given instance inward your eclipse past times changing the values of variables.
public shape IfStatements { world static void main(String[] args) { int i = 25; int j = 50; int k = 24; //Simple If statement System.out.println("***Simple If Statement Example***"); if (i<j) //Bellow given message volition last printed alone if value of variable i is less than value of variable j. System.out.println("Value Of i("+i+") Is Smaller Than Value Of j("+j+")." ); //If Else Statement System.out.println(""); System.out.println("***If Else Statement Example***"); if (i>=j)//Bellow given message volition last printed if value of variable i is greater than or equals to value of variable j. { System.out.println("Value Of i("+i+") Is Greater Than Or Equals To Value Of j("+j+")." ); }else//Bellow given message volition last printed if value of variable i is less than value of variable j. { System.out.println("Value Of i("+i+") Is Smaller Than Value Of j("+j+")." ); } //Nested If Else Statement System.out.println(""); System.out.println("***Nested If Else Statement Part***"); if (k<i)//Bellow given message volition last printed if value of variable k is less than value of variable i. { System.out.println("Value Of k("+k+") Is Less Than Value Of i("+i+")" ); }else if (k>=i && k<=j)//Bellow given message volition last printed if value of variable k is greater than or equals to value of variable i in addition to less than or equals to value of variable j. { System.out.println("Value Of k("+k+") Is In Between Value Of i("+i+") And Value Of Value Of j("+j+")" ); }else //Bellow given message volition last printed if value of variable k is greater than value of variable j. { System.out.println("Value Of k("+k+") Is Greater Than Value Of j("+j+")" ); } } }
Bellow given output volition last printed inward your eclipse console when you lot volition run inward a higher house example.
***Simple If Statement Example*** Value Of i(25) Is Smaller Than Value Of j(50). ***If Else Statement Example*** Value Of i(25) Is Smaller Than Value Of j(50). ***Nested If Else Statement Part*** Value Of k(24) Is Less Than Value Of i(25)
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM
http://www.software-testing-tutorials-automation.com/