Tutorialslot.com

youtube facebook twitter gmail pinterest

If-else in Java


It consists of two parts namely the if part and the else part.When the condition in "if" is true then statements present in if part will be executed otherwise statements present in the else part will be executed.

Syntax:
if(condition)
{
statement-1;
}
else
{
statement-2;
}

Example:
public class IfElse
{
public static void main(String args[])
{

int test=2;


if(test>1)
{

System.out.println("if else program is Success");
}
else
{

System.out.println("if else program is Failure");

}


System.out.println("Successfully Executed if else program");
}
}

Output:
if else program is Success
Successfully Executed if else program



Advertisement Powered By Google Adsense






IF YOU LIKE THIS TUTORIALS PLEASE SHARE

Share on whatsapp

POPULAR TAGS

Java java tutorials learn java java programming tutorial learn java online learning java professionals tutorials Multithreading Generics Object Oriented Language Methods Polymorphism Inheritance