Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Flow Control Conditional Statement

Previously, we have seen that what are Assignment Operators in Java programming language. In this video, we are going to see what are Control flow statements in Java.

There are basically three types of Control Flow statements in Java. They are also called as Itration statement in Java. The following are the three Control flow statements in Java,

  • If statement in Java
  • If else statement in Java
  • Switch statement in Java

An if statement in Java consists of a boolean expression followed by one or more statements.
Syntax :
if(Boolean_expression)
{
//Statements will executive the Boolean expression is true
}

Now we will do Programming for if statement in Java to understand it in practical way.
class Test
{
public static void main (String args[])
{
int x=10;
if(x<20)
{
System.out.println("x is greater");
}
}
}
Output :
x is greater

Note: An if statement in Java can have zero else's.

Now we will do Programming for if else statement in Java.
class Test1
{
public static void main (String args[])
{
int x=30,y=40;
if(x>y)
System.out.print("x is greater");
}
else
{
System.out.print("y is greater");
}
}
}
Output :
y is greater

Note : An if else statement in Java can have zero or one else's and it must come after any else if's. Once an else if succeeds, none of the remaining else if's or else's will be tested.

Now we will do Programming for Nested else if statement.
class Test2
{
public static void main (String args[])
{
int x=30;
if(x==10)
{
System.out.print("Value of X is 10");
}
else if(x==20)
{
System.out.print("Value of X is 20");
}
else if(x==30)
{
System.out.print("Value of X is 30");
}
else
{
Sytem.out.println("This is else statements");
}
}
}
Output :
Value of X is 30

A Switch statement in Java is useful when you need to select one of several alternatives based on the value of an integer, a character, or a String variable.
Syntax :
switch(expression)
{
case value1:
//statements
break;
case value2:
//statements
break;
default:
//statements
break;

So this are all the Control flow statements in Java. We have covered all the three different types of control flow statements in Java with example for better concept clearance. Now in the next video we will see that what are Looping statements in Java and what are the different types of Loops in Java programming language.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere