Multiple if and If-else control structures.

In this article,Multiple if and If-else control structures are explained in detail with examples.
In this control structure, we use multiple if statements one after the other/sequential as follows.
Syntax
if(condition 1)
{---
body1;
---
}
if(condition 2)
{---
body2;
------
}

if(condition 3)
{----
body 3;
---
}
next statement;
---
In this control structure, every condition is checked one after the other and whichever condition is true, its corresponding body is executed. If no condition is true then, the control comes directly to the next statement. (From topic Multiple if and If-else control structures)

Ex
//Program related to Multiple if and If-else control structures--multipleif-statement.
class MultipleIfStatement
{
public static void main(String args[])
{
char ch='$'; //local variable.
ch='x';
if(ch=='x')
{
System.out.println("Given char: "+ch);
}
if(ch=='y')
{
System.out.println("Given char: "+ch);
}
if(ch=='z')
{
System.out.println("Given char: "+ch);
}
System.out.println("End of the program");
}
}
Output
Multiple if control Structure-javaform

Ex
//Program related to Multiple if and If-else control structures--multipleif-statement.
class MultipleIfStatement
{
public static void main(String args[])
{
char ch='$'; //local variable.
ch='y';
if(ch=='x')
{
System.out.println("Given char: "+ch);        //(From topic Multiple if and If-else control structures)
}
if(ch=='y')
{
System.out.println("Given char: "+ch);
}
if(ch=='z')
{
System.out.println("Given char: "+ch);
}
System.out.println("End of the program");
}
}
Output
Multiple if-javaform

Ex
//Program related to Multiple if and If-else control structures--multipleif-statement.
class MultipleIfStatement
{
public static void main(String args[])
{
char ch='$'; //local variable.
ch='z';
if(ch=='x')
{
System.out.println("Given char: "+ch);
}
if(ch=='y')
{
System.out.println("Given char: "+ch);
}
if(ch=='z')
{
System.out.println("Given char: "+ch);
}
System.out.println("End of the program");
}
}
Output
Multiple If-javaform

Ex
//Program related to Multiple if and If-else control structures--multipleif-statement.
class MultipleIfStatement
{
public static void main(String args[])
{
char ch='$'; //local variable.
if(ch=='x')
{
System.out.println("Given char: "+ch);
}
if(ch=='y')
{
System.out.println("Given char: "+ch);
}
if(ch=='z')
{
System.out.println("Given char: "+ch);
}
System.out.println("End of the program");
}
}
Output
Multiple if.-javaform
                            To get the code file use me.
If -else Control Structure.
In this control structure, we use the true parts block as well as the false part block as follows.
Syntax
if(condition)
{
true part;
}
else
{
false part;
}
next statement;
-----
Note
Here if the condition is true,then true part is executed and control comes to next statement.If the condition is false then control comes to else part i.e. false part and also comes to next statement.

Ex
//Program related to Multiple if and If-else control structures--if else branching
class IfElseBranching
{
public static void main(String args[])
{
char ch;
ch='x';
if(ch=='x'|| ch=='y' || ch=='z')
{
System.out.println("Given char:"+ch);
}
else
{
System.out.println("Given char unknown");
}
System.out.println("End of the program");
}
}
Output
If else control Structure-Javaform

Ex
//Program related to Multiple if and If-else control structures--if else branching
class IfElseBranching
{
public static void main(String args[])
{
char ch;
ch='y';
if(ch=='x'|| ch=='y' || ch=='z')
{
System.out.println("Given char:"+ch);
}
else
{
System.out.println("Given char unknown");
}
System.out.println("End of the program");
}
}
Output
If else Control Structure-javaform

Ex
//Program related to Multiple if and If-else control structures--if else branching
class IfElseBranching
{
public static void main(String args[])
{
char ch;
ch='z';
if(ch=='x'|| ch=='y' || ch=='z')
{
System.out.println("Given char:"+ch);
}
else
{
System.out.println("Given char unknown");
}
System.out.println("End of the program");
}
}
Output
If else control Structure-Javaform

Ex
//Program related to Multiple if and If-else control structures--if else branching
class IfElseBranching
{
public static void main(String args[])
{
char ch;
ch='A';
if(ch=='x'|| ch=='y' || ch=='z')
{
System.out.println("Given char:"+ch);
}
else
{
System.out.println("Given char unknown");
}
System.out.println("End of the program");
}
}
Output
If else Control Structure-Javaform

continue to the next topic Nested if control structure.

Begin your career in Digital Marketing,What is digital marketing? Digital Marketing online course. It's an current evolving technology which can give support to establish your own startup through Digital Marketing

Do check my new startup Surprise Planners in HyderabadLavish Surprises our services are surprise party planners in Hyderabad, surprise giftssurprise birthday party planners Hyderabad, Wedding anniversary surprises, surprise planners Hyderabad.

Hi Friends, Please comment down your views in the comment section below. Thank you...

No comments:

Connect with Us by Subscribing here for more Updates..!

* indicates required