Session 4- Working with Java Conditional Statements | Java & Selenium
Estimated read time: 1:20
Learn to use AI like a Pro
Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.
Summary
In this session, the focus is on Java conditional statements, a fundamental topic for controlling program execution. The instructor elaborates on how statements are executed sequentially in Java, and introduces control statements as tools to alter the flow based on conditions. Key concepts include conditional statements like if, if-else, nested if-else, and switch case statements. Examples demonstrate practical usage through age eligibility checks, identifying even or odd numbers, and using nested conditions for complex logic. Emphasis is placed on the importance of control statements in crafting efficient and logical code structures.
Highlights
Java executes statements sequentially unless control statements modify the flow. 🏃♂️
Conditional statements include if, if-else, nested if-else, and switch statements. 💡
Switch case statements decrease line count and increase code efficiency. 💪
Examples included finding the largest number among three and identifying week's day name. 🗓️
Assignments encourage practice with ternary operators and conditional logic setup. 📝
Key Takeaways
Conditional statements in Java are essential for directing program flow based on conditions. 📜
The 'if' statement executes a block only if the specified condition is true. 🔍
'If-else' structures allow alternate execution paths based on a condition's truthfulness. 🔀
Nested if-else statements can be used for more complex logic by incorporating multiple conditions. 📚
Switch case statements simplify complex conditional logic by reducing code size. 🚀
Overview
Welcome to this detailed exploration of Java conditional statements, a crucial element for any programmer looking to control the flow of Java programs effectively. Today, we're diving deep into how conditions can govern which parts of your code execute, turning linear logic into dynamic and adaptable processes.
We kicked off with fundamental concepts—if statements allow specific code execution only when conditions you set are true. But what happens when they are not? That's where if-else statements come into play, providing alternative code paths and giving your program the power to adapt in real-time based on inputs.
Moving into more intricate territory, nested if-else structures offer the ability to stack conditions within conditions, crafting more sophisticated decision trees. For sheer volume of decision-making, switch case statements become invaluable, condensing otherwise hefty conditional logic into streamlined simplicity. Our session is peppered with practical examples, from checking ages to see if someone can vote, to discovering if a given number is a particular week’s day.
Chapters
00:00 - 01:00: Introduction to Java Control Statements This chapter introduces Java control statements, explaining their importance in programming. It begins with a recap of the previous lesson on operators and transitions into the new topic of control statements. The chapter discusses the default top-to-bottom flow of execution in Java applications, setting the stage for explaining how control statements can modify this flow.
01:00 - 02:00: Understanding Execution Flow The chapter "Understanding Execution Flow" discusses how code execution typically proceeds in a sequential manner, from top to bottom, executing each statement one after the other. It explains that regardless of the number of statements written, this sequential execution order is maintained. Additionally, the chapter touches on conditional execution, where specific statements can be executed based on certain conditions, allowing for more targeted control over the execution flow.
02:00 - 03:00: Control Statements Overview Control Statements allow the execution of specific code blocks based on certain conditions, meaning not all statements in a program have to be executed each time. This enables selecting and executing only particular statements or groups of statements based on defined conditions, optimizing program behavior.
03:00 - 04:00: Conditional Statements The chapter introduces the concept of conditional statements, emphasizing how groups of statements can be executed based on certain conditions. It then transitions into a discussion on loops, explaining that these allow for the repetition of a set of statements multiple times, based on certain conditions. This repetition of steps forms the core concept behind loops.
04:00 - 05:00: If Statement Explanation The chapter titled 'If Statement Explanation' focuses on the use of conditional statements to control the execution of a program or code. It highlights the importance of loops and how they allow for the repeated execution of statements multiple times. This chapter primarily delves into how control statements, particularly the 'if' statement, can be utilized to determine the flow of execution based on certain conditions. Additionally, it mentions the existence of three kinds of control statements that help in managing the program's control flow.
05:00 - 06:00: Using If Statement in Eclipse This chapter introduces control statements in Java, with a particular focus on using 'if statements' in Eclipse. It categorizes control statements into three types: conditional statements, looping (or iterative) statements, and a third unstated type. The chapter emphasizes the role of control statements in directing the execution flow of a program or a piece of code in Java.
06:00 - 07:00: If-Else Statement Introduction Chapter Title: If-Else Statement Introduction
This chapter introduces control statements focusing on conditional statements such as if-else. The chapter explains the various types of control statements available - conditional, looping, and jumping statements - and emphasizes their role in controlling the execution order of a program. It indicates that the current session focuses on conditional statements, while looping and jumping statements will be covered in subsequent sessions.
07:00 - 08:00: If-Else Statement Example The chapter introduces the concept of conditional statements in Java, highlighting four types: 'if condition', 'if-else condition', 'nested if-else', and 'switch case'. These are fundamental structures for decision-making processes in Java programming.
08:00 - 09:00: Number Checking: Even or Odd The chapter discusses the use of conditional statements in Java to determine whether a number is even or odd. It introduces four types of conditional statements that are supported: if, if-else, nested if-else, and switch case. The chapter aims to demonstrate the practical application of these statements in various scenarios with examples.
09:00 - 10:00: Checking Positive, Negative or Zero Numbers The chapter explains how to use the 'if' condition in programming. The syntax is demonstrated, showing that you place a condition within the 'if' statement, and if the condition evaluates to true, the code block inside the 'if' statement is executed. This forms the basic structure of using conditional statements to control the flow of the program.
10:00 - 11:00: Finding the Largest of Three Numbers The chapter titled 'Finding the Largest of Three Numbers' elucidates the concept of conditional statements in programming. It explains that certain statements are executed only if a given condition is true. The chapter emphasizes that if a condition evaluates to false, the corresponding block of code is ignored and not executed. It provides an introductory explanation of using 'if' conditions, including the syntax which entails specifying conditions within parentheses and enclosing the dependent statements within a block. The chapter promises a demonstration of these concepts through examples, although the transcript is incomplete. Overall, it focuses on the basic understanding of conditional logic in determining the largest of three numbers.
11:00 - 12:00: Multiple If-Else Conditions The chapter titled 'Multiple If-Else Conditions' begins with an introduction to Eclipse project setup. The instructor creates a new package named 'day four' within the project. The focus shifts to using conditional statements in programming, specifically the 'if' condition. A new class is created named 'if condition demo' which includes the main method for demonstrating the use of simple 'if' conditions in programming.
12:00 - 13:00: Nested If-Else Statements The chapter delves into the concept of nested if-else statements in programming. It begins with an illustration of a problem statement where a person's age is taken as a variable for evaluation. In this scenario, the nested if-else statement is used to determine whether the person meets specific eligibility criteria, such as being eligible to vote if their age is 18 or older. The chapter emphasizes the importance of conditional logic and how nested if-else structures can be used in decision-making processes.
13:00 - 14:00: Displaying Week Names Based on Number The chapter titled 'Displaying Week Names Based on Number' seems to discuss eligibility verification based on age, specifically for overtime (OT). It begins with introducing a simple variable 'person age' set to 25, followed by instructions on how to check if this person is eligible for OT or not. The text suggests that if the person's age is greater than or equal to 18, they are considered eligible for 'order'. However, the explanation focuses on how to verify this condition programmatically, leaving the detailed coding logic incomplete.
14:00 - 15:00: Introduction to Switch Case Statement The chapter introduces the concept of the switch case statement focusing on conditional statements, emphasizing its usage with an example of determining a person's eligibility to order based on age. It highlights the logic where the person's age, stored in a variable, must be greater than or equal to 18 to return true, thus allowing an order.
15:00 - 16:00: Writing Efficient Code with Switch Case This chapter discusses using the switch-case statement in programming to effectively write efficient code. It starts by explaining a relational operator, 'greater than or equal to,' which compares values to return a boolean. This operator is used to determine if a value meets a certain condition (e.g., a person’s age being greater than or equal to 18). The true or false outcome of this comparison will dictate the flow of control within the code. Essentially, this chapter emphasizes the importance of Boolean expressions in decision-making structures, explaining that they provide a technique to control program behavior based on conditional logic. The importance of using Boolean expressions is highlighted as a cornerstone of writing efficient and effective control flow statements in a program. To implement this logic in a structured manner, switch-case statements can be employed to handle discrete values and execute corresponding code blocks for each case that meets the specified condition.
16:00 - 17:00: Switch Case Syntax and Usage The chapter titled 'Switch Case Syntax and Usage' explains how to implement control flow based on conditions in programming using switch-case statements. The transcript highlights that when an expression returns true, the code block within the brackets is executed. The example used is a system print line statement indicating eligibility, which executes only when a condition is met. If the expression returns false, then the specified statement block will not execute. This demonstrates the use of conditional logic to control the execution of code based on boolean expressions.
17:00 - 18:00: Implementing Switch Case for Week Names The chapter titled 'Implementing Switch Case for Week Names' seems to be discussing how conditional statements operate, specifically focusing on the switch-case control structure. It emphasizes the concept where a condition is evaluated, and if it is true, a specific block of code is executed. The provided transcript snippet suggests that the discussion involves basic condition evaluation, such as checking if 25 is greater than or equal to 18, as an illustration of how such conditional statements work. The chapter likely continues to explore how these principles apply to implementing switch-case for week names.
18:00 - 19:00: Assignments Based on Conditional Statements The chapter explains the execution of a Java application based on conditional statements. It showcases how an expression determines the execution of a statement, using an example where a condition checks if a certain age is greater than or equal to 18. Initially, the condition evaluates to true, leading to a successful execution of the statement. However, when the age is changed to 15, the condition evaluates to false, resulting in no output.
Session 4- Working with Java Conditional Statements | Java & Selenium Transcription
00:00 - 00:30 okay so in the last class uh we have seen how
to work with the different type of operators in Java now today let's continue with the some
more important topics uh some Basics uh control statements so the next topic control statements
so normally uh when you write your Java program and when you're executing it so the statements
will be executed top to bottom let's say if you
00:30 - 01:00 have written 10 statements or 100 statements so
the execution will always happens top to bottom so each and every statement will be executed
in sequential manner let's say these are the different statements and execution will happen
like this so each and every statement will be executed right but sometimes uh if we want
to execute a specific statements based upon certain condition let's say now I want to
execute only this particular statements based
01:00 - 01:30 upon certain condition and I want to execute
another set of statements based off another condition that means every time you don't need to
execute the same set of statements So based upon the condition we can also choose the statements
which we want to execute okay this is basically called uh controlling uh your statements means
instead of executing each and every statement in your program we can select set of statements or
group of statements and we can execute only those
01:30 - 02:00 group of statements based on certain condition
okay this is one scenario another scenario is suppose I have set of number of statements and I
want to repeat the same statements multiple times again and again based upon certain condition I
want to repeat the same steps same statements again and again multiple times this is basically
called as a loop and we can execute the same set
02:00 - 02:30 of statements multiple times repetitively we call
it as a loop and we can execute set of statements based upon certain condition this we can achieve
by using conditional statements so basically we can control the execution of your program or
execution of your code by using control statements there are three kinds of control statements and
by using those control statements we can control
02:30 - 03:00 the execution of your program or execution
of your code so mainly there are three kinds of control statements are there in Java so the
first type is conditional statements conditional statements conditional statements and the second
is looping or item ative statements and the third
03:00 - 03:30 is jumping statements so these are the three
kinds of control statements which we have so what is the use of these control statements we
can control the execution of your program or can control the execution order of your program that
we can achieve by using conditional statements or looping statements or jumping statements so
we will discuss today conditional statements mainly conditional statements and of them
we'll discuss in the next sessions so what
03:30 - 04:00 are the conditional statements are available
in Java so there are four types of conditional statements conditional statements there are
four types of conditional statements one is uh only if condition if condition second is
if else condition third is nested if Els and fourth is is switch case so these are the four
different conditional statements supported in
04:00 - 04:30 Java so the purpose of using the conditional
statements is same but we will use these statements the different scenarios if if Els
nested if Els and then we have a switch case statement so these are the four different type
of conditional statements supported in Java so now we'll see practically how can we use these
conditional statements and where we can use this conditional statements with the different type
of examples so the first condition statement is
04:30 - 05:00 if so how to use this if condition the syntax
of if condition is like this if and uh here we put some condition and if this condition is
true then whatever steps we want to execute or whatever statements we want to execute we
can keep those statements inside this block so this is called syntax how to use if condition
so if this condition condition is true then only
05:00 - 05:30 these statements will be executed if this
condition is false these statements will be ignored these statements will not be executed
so this is only if a condition let me show you how to use this and there is no semicolon for if
condition okay if you need to put some condition Open Bracket closing bracket and what are all
statements you want to execute based on the condition we can specify them inside this block
now let me show you some example examp go to
05:30 - 06:00 eclipse and this is our project which we already
created now today is day four let's create new package day four and click on finish so how
to use if condition only if condition so let's create a new class and I'll name it as
if condition demo take this main method also
06:00 - 06:30 and then say finish okay so now my requirement
is uh my problem statement is for example uh I will take a person age as a variable let's say in
person uncore age equal to let's say 25 this is the variable I have created now my requirement
is I want to check this person is eligible for o or not so according to my condition if the
person age is greater than or equal to 18 He
06:30 - 07:00 is eligible for OT that I want to verify okay so
I have simple a variable created person age equal 25 now I want to check this person is eligible
for V or not so if you want to check this person is eligible for what simply we can check the
condition if the person age is greater than or equal to 18 we can simply say he is eligible for
order but how can we verify that condition how we can check this person age is greater than
or equal to 18 or not so now we can write one
07:00 - 07:30 conditional statements so if condition can use
if in the bracket we can specify the condition what is our condition the person age should
be greater than or equal to 18 then only he is eligible for order so here I'm taking that
variable whatever variable I defined that is person uncore age that should be greater than or
equal to 18 so will it return true or false this
07:30 - 08:00 what is that operator we have used here greater
than or equal to which is a relational operator right so what is relational operator will do
here it will compare the personage is greater than or equal to 18 or not and if it is greater
than or equal to 18 it will returns true if it is not return false that means here we have to
always specify a Boolean expression here we have to always write a Boolean expression which will
return return true or false so if the condition is
08:00 - 08:30 true if the expression is return true then we can
specify the statements which we want to execute based on the condition here inside this bracket
I can say system. println eligible eligible for p like this you can specify now this particular
statement will execute only if this condition is return returns true only if this expression
is returns true then only this state will be executed and if this statement is written false or
if the expression is written false the statement
08:30 - 09:00 will not be executed that means based on the
condition we are executing this statement if the condition is true execute the statement if
the condition is false then don't execute the statement okay for example let's say I'm taking
25 25 is greater than or equal to 18 or not yes the condition is true true so if the condition is
true then obviously the statement will be executed
09:00 - 09:30 so when I execute run as a Java application so
now we can see the output here so statement is got successfully executed because the expression
is WR true now I'll just make this as a 15 now the personage is 15 15 is greater than or equal to
18 expression return false so if it is a false the statement should not be executed now when
I run this code you will not get any output in
09:30 - 10:00 the console window so no output because we are not
specify anything else other than the statement so only one statement be specified and this will
be executed only if this expression is return returns true right so this is how we can simply
use if condition if the expression returns true statement will be executed if the expression
return false statement will not be executed so this is how we can simply use if condition
only if condition but if it is not true then
10:00 - 10:30 what should happen we haven't specified that we
haven't specified that suppose if the condition is false what should happen if the condition is
true the statement will execute if the condition is false what should happen that we haven't
specified here so this is only if a statement we haven't specified any else this is only if
a statement if the condition is true statement will execute if the condition is false state will
not be executed that's it only if condition the
10:30 - 11:00 first one okay but sometimes we should also
specify else part that means if the condition is not true then what should happen that also we
have to include right so for that we use another statement if along with else if block along with
else this is called a block you can put one single statement here or you can put multiple statements
also allowed in if condition you can keep single
11:00 - 11:30 statement or multiple statements okay sometimes
if the condition is false then what should happen that also we can specify in the else block so
this is only if condition okay now how can we use if and else block combinations so the syntax
will be like this if we put one condition if the condition is true then the group of statements
will be executed and and if this condition is
11:30 - 12:00 false for example if this condition is false
then we write another block called else block like this so if the condition is true then these
set of statements will execute if the condition is false then else block will execute inside the
else block also we can write the statements okay now if the condition is true if block will
execute if the condition is false then else block will automatically execute this is alternate
okay now this is called if else condition if else
12:00 - 12:30 condition okay so how to use this ifs condition
so let's say uh save this let me create another class suppose if condition is
uh if condition return return false so then what we should happen
let me just rename it this is if El
12:30 - 13:00 condition okay so this is a if else condition same
program I'm taking the person age if person AG greater than or equal to 18 He is eligible for and
if this condition is false then what we should do else we have to write else Block in else block we
can specify and what we can specify not eligible
13:00 - 13:30 not eligible for what like this so based on the
condition we are choosing the statements right if the condition is true if block will execute if
the condition is false else block will execute at a time only one block will be executed both
will not be executed because the condition uh will return true or false right if it returns
true if block will execute if returns false
13:30 - 14:00 else block will execute now when I say 15 the
condition is false the expression will return false so obviously else block will execute okay
so not eligible for either this one or this one only one block will be executed always okay so
this is how uh we can use El okay so if condition and then else along with else and you should
not put semicolon for if condition like this
14:00 - 14:30 okay for else also should semicolon only the
statements which we have included inside this block we have to specify the statements okay so
if and else block like this fine so sometimes you may have multiple statements inside this okay so
here if you have a single statement you can put multiple statements or single statements suppose
if you have a single statement here the brackets
14:30 - 15:00 are optional okay the curly braces are optional
you can directly keep the statement inside with condition and here also if you have one single
statement in the lse block these brackets are optional okay so let me show you so currently
I have single statement in every block right so what I will do is I'll try to remove the I
will try to remove the C braces just observe
15:00 - 15:30 this okay now just observe here I just try to
remove the Carly press and here also I'll Remo it okay so now just observe when I running this
so you will get a not eligible for now I'll take another number 25 and you will get eligible
forward so how come it is executing so that
15:30 - 16:00 means if you have a single statement under the
condition you no need to specify the curly braces you can directly write under this so if the
condition is true the statement will execute and if the condition is false else statement
will execute so if you have a single statement you no need to put in the CRA but if you have a
multiple statements you have to include them in the curly braces okay so what I will recommend is
even though if you have a single statement better
16:00 - 16:30 to keep inser the curly brace why because you
clearly know whether the statement is belongs to this condition or not so by seeing the code
you will understand this particular block will be executed based upon this condition okay so
if you have a single statement curly braces are optional and if you have a multiple statements you
should keep inside the curly places okay that is another one you can just remember this so This
is called if else condition so if condition is
16:30 - 17:00 true if block will execute if the condition is
false else block will execute at a time only one block of statements will be executed okay now
let me show you one more example for if else condition so the first example we have already
seen elig ible for V or not now the example
17:00 - 17:30 two so suppose we Define one number and we need to
find out that number is even or odd number so we provide one number and that number we have to find
even number or odd number through our program okay so how to find out so normally if I ask you if I
give some number like this let's say I've given 10 so if I ask you whether it is even number or odd
number how we will tell how we will know whether
17:30 - 18:00 it is even number or odd number we will simply
say it is an even number when you say five you can simply say which is an odd number but how we
will know whether this is even number or not this is even number and this is odd number so how we
will know whether is even number or odd number so we have some mathematical calculation behind that
right so if any number divided by by two returns
18:00 - 18:30 zero as a remainder that is an even number okay
for example let's say if I take any number let's say 10 10 ided 2 returns zero as a remainder
that is a even number right and 10 ided by two suppose 5 divided by two which is written one as a
remainder so other than zero whatever remainer you will get other than zero they all comes under odd
numbers it can be one or it can be anything else
18:30 - 19:00 right this is a mathematical calculation simply we
can say so if you want to say a number is a even number that number divided by two should return
zero as a rem remainer and if you want to say a number is an odd number when it divided by number
by two that should return non zero other than zero you will get any number as a reminder that is an
odd number that is a logic so now programmatically we have to find a number is even number or odd
number okay and how can we find out so again based
19:00 - 19:30 on the condition if a number divided by 2 equal to
Z if condition is true then we can say even number and if not we can simply say odd number so based
on the condition we can check so how can we use if Els condition here let me create a new class even
or odd number so how to check a number is even
19:30 - 20:00 number or odd number so what we can simply say
first we'll take one number in number equal to 10 so I have taken I have defined one variable right
so now we need to find this number is even number or odd number so how can we check if this number
divided by two divided by two which is returning
20:00 - 20:30 zero and uh which operator we have to use here W
equal to or equal to equal or equal to which one we have to use condition if number percentage two
returns zero as a remainer we we have to compare this the remainder whatever is written by this
expression should equal to zero or not we want to compare so we have to use comparison operator
that is double equal to right so if number percent
20:30 - 21:00 two why we are using percentile instead of Slash
because percentile operator will return reminder right it is also division operator but it will
return return the remainer that we want to check so number percent 2 equal to0 that means if
this is true when this expression true if number percent Del to returns zero then this expression
will returns true overal expression right Boolean
21:00 - 21:30 value will be return so if this condition is
true then what we can simply say that number is even number okay that number is even number and
other than zero okay you suppose this condition Falls whenever the remainder is non zero that
means other than zero if it is return any other value this condition become false so in that
case what we can simply say it is a odd number
21:30 - 22:00 that you can specify in else block else block we
can say system. print odd number like this so at a time only one statement will be executed based
on the condition so if the condition is true if block will execute if the condition is false else
block will execute so when I execute this it will
22:00 - 22:30 say Java application even number so we can say 10
right so 10 is a even number let's say 15 15 now condition is false so obviously else block will
execute which is odd number okay so this is how we can simply use if else condition okay if FSE
condition we can use now let me show you some more
22:30 - 23:00 examples example three we can practice so many examples like this
is and number of examples you can find so now I want to check a number is positive negative or
zero check a number is positive or negative or
23:00 - 23:30 zero so if I provide a number as an input and
the program should display whether that number is positive number or negative number or zero so
normally how can we check a number is positive negative or zero as per mathematical calculation
how can we verify number is positive negative or zero how can we say on what basis we can
say a number is positive negative or zero
23:30 - 24:00 positive negative or zero how can we find yes simple calculation right if any
number which is greater than zero that is positive number right if any number if I take any
number as a variable if that is greater than zero obviously that is a positive number right and if
the number is less than zero that is a negative
24:00 - 24:30 number that is a negative number and if the
number is equal to zero obviously that is a zero only right so we have multiple conditions
here so far we have seen only one condition one if condition so sometimes we have to write
multiple if conditions multiple conditions we have to verify if the number greater than zero say
POS POS if the number less than zero say negative
24:30 - 25:00 if the number equal to zero then say zero so here
we have to check multiple conditions if you have only one condition then we can use only one if
one statement one if statement here just like this if condition is true block will execute if
the condition is false another block will execute only one single condition which we have here but
if have a multiple conditions in case if we have a multiple conditions then how we can specify that
so let me show you one more example take another
25:00 - 25:30 class positive or negative number okay so how can we specify the multiple
conditions okay first of all let us take a number in number equal to let's take zero first the
number value is zero now we want to check which is zero or positive or negative okay so the what
is the first condition if this number greater than
25:30 - 26:00 zero if this number greater than zero then what
we can say here it is positive number which is positive number fine suppose if this number is
not greater than zero so condition is false then we have to verify another condition right how to
verify another condition we can write like this
26:00 - 26:30 else if else if again one more condition number
less than zero then what we can say here system is a negative number it's a negative number even
this condition is also false for example number is not negative less than zero then what we can
specify the last option which we have that is zero only right so else here you can say system.
out. zero like this so multiple conditions we can
26:30 - 27:00 also verify by writing multiple if conditions so
if number greater than zero execute the statement if this condition is false else one more if
condition else number less than zero execute this statement even this condition is also false
then else last statement will be executed so else
27:00 - 27:30 block else block will always execute if none of
the conditions are true okay if all of the if conditions are false finally else block will
execute so here we only need to put another condition again you only need to write else
if number equal to zero not needed because obviously else block will execute after execution
of these two statements after execution of these two conditions if both the conditions are written
false then finally else block will automatically execute so if you have a multiple conditions you
can also write like this else give one space and
27:30 - 28:00 then if so the structure will follow like this
this is called uh if else later we can call it as a if else later so the syntax will be like
this if condition one first condition okay else if they're not satisfied else one more condition
if condition two and statements and even second
28:00 - 28:30 condition is not possible not returns true then
again one more condition else if condition three you can put any number of condition like this
even this is also not satisfied then else one more condition else if condition four like this
and if all conditions are done so finally if none of the conditions are becomes true finally you
can write only one else blog like this this is
28:30 - 29:00 called if else later if else later so this is
the syntax which you have to use you can put any number of conditions if condition one is true
statements will execute in this blog else another condition is true then execute the statement
even this condition is also false then third condition it will verify even third condition
is false then fourth condition will verify even this is also false finally block will execute
so like this you can put any number of levels
29:00 - 29:30 different levels and different conditions you can
specify okay now let us test this code at a time only one block of statement will be executed so
initial I say number equal to zero so when I say number value zero obviously it will return zero
as an output now when I say 10 then is a positive number which is greater than zero so when I
execute it is written positive number so when I say minus 10 minus - 10 is a negative number so
when I execute it is written negative number the
29:30 - 30:00 second block is got executed okay so at a time
only one block of statements will be executed based on the condition we can control it okay now
let me show you one more example so we can also use sometimes logical operators in the conditions
okay so let me show you one more example example
30:00 - 30:30 four so in example four uh is we want to find
largest of three numbers largest of three numbers or you can call anything okay largest
of three numbers I want I will provide three
30:30 - 31:00 numbers the program should find out which one is
the largest number okay for example uh let's take three variable let's say a = to 10 B = to 20
C = to 30 like this now program should say C is the largest number or if B is the larger then
program should find out and say B is the largest number or a is the largest number okay so before
writing the program so nor normally let us think about the logic how can we find a largest number
if I give these three numbers immediately we will
31:00 - 31:30 say C is the largest number but how come you say
C is the largest number on what basis you are saying C is the largest number do you have any uh
mathematical thing here calculation to say which one is the largest number how we are saying
actually we comparing each number with other numbers right so for example if a greater than b
okay a greater than b and also a greater than C
31:30 - 32:00 then we are saying a is the largest number right
this is a condition or not first we are taking one number we comparing with the rest of the two
numbers if this number is greater than rest of two numbers obviously that is the largest number
same we are repeating for other numbers also for example if I take b b is greater than a a and also
B greater than C then we are saying what B is the
32:00 - 32:30 largest number B is a largest number same thing we
are repeating for C also if C greater than a and C greater than b also then obviously C is a largest
number so based upon certain condition we are saying after comparison we are seeing each number
we are comparing with other numbers so if that number is if the particular number is greater than
other two numbers we are saying that is a largest
32:30 - 33:00 number or which a greater number so these are the
actual conditions now the same conditions we have to apply in your programming also so if you want
to say which one is the largest number we have to use multiple conditional statements okay and one
if condition we can put multiple also right so this we can achieve uh by writing multiple if Els
conditions so let's see how can we implement this
33:00 - 33:30 practically so let's create a new class
and here I'll say largest of three numers take this main method and say
finish okay same logic we will try to apply here
33:30 - 34:00 I keep this so that we can understand
the conditions okay these are the three conditions to say largest of three numbers we
have to verify these three conditions okay I put this in the comment so that you can understand
the logic now let us try to implement this first of all we need three numbers let's create three
different variables int a = 10 comma B = 20 comma C = 30 now I have taken three numbers three
variables now I want to find out which one is
34:00 - 34:30 a largest number so first let us compare a with b
and c okay what is the first condition we have to check a greater than b and a greater than C then
we will say a is a largest number right so what we can do it here is first condition if a greater
than b this is one condition another condition
34:30 - 35:00 is what a greater than C both the conditions
should be true then only we can say a is the largest number a greater than b should be true
a greater than C also should be true if both are true then only a is the largest number a greater
than b returns true that means a Boolean value a greater than C also should returns true that is
also Boolean value and if both are true then only we can say a is the largest number right so in
that particular context which operator we have
35:00 - 35:30 to use between these two Boolean values both
should be true then only the final value should be true so which operator we have to use between
these two expressions end operator end is what logical operator okay so here a greater than b
and a greater than C so this time we specified two expressions remember this is one condition
this is another condition both should be wrs
35:30 - 36:00 true then only the final condition becomes true
okay inside this we have written two expressions a greater than b and a greater than C both should
returns true then only the if condition becomes true okay even if one is false then if condition
will become false so in both Expressions both both the Expressions it should both returns true so
the if condition is true then what does it mean
36:00 - 36:30 here we can simply say a is largest number a is
the largest number so first validation is done so this is done now suppose if this condition
is false what does it mean if this condition is false what does it mean a is a not largest number
right if a is the largest number OB viously this if condition becomes true if this if condition is
not becomes true what does it mean indirectly a is
36:30 - 37:00 a not largest number so we need to compare next
number what is the next one b b greater than a and b greater than C then B is the largest number
so how can we put another condition else if one more condition so here we can say a greater than
b sorry B greater than a and B greater than C so now we are comparing B with A and C so if both
are true then this if condition becomes true so
37:00 - 37:30 here we can say system B is a largest number B
is a largest number so now the second condition is also over now suppose even this condition is
also Al return false so first condition checks
37:30 - 38:00 a is largest or not second condition check B
is largest or not if both the conditions are false what does it mean obviously C is the largest
number is there any other case here nothing right if both conditions are false then obviously C is
the largest number so do you really want to put this condition not needed right so directly you
can write in else block condition is not needed you can simply right system C is largest number
so for comparison of C there is no condition not
38:00 - 38:30 required why because here we decided a is not
largest number if it is false if the second condition is foral B is not largest obviously
what is the other number we have is only C so we can say in lse blog we can simply say C is the
largest number so this will execute only if about two conditions are written false so about two
conditions written false means what A and B are
38:30 - 39:00 not largest numbers obviously the C is a largest
number so this is how we can implement the logic and here if I notice we are using logical
operators along with relational operator the combinations because logical operators also
will L true or false the if a condition required a Boolean value that expression whatever we have
written is should return a Boolean value in the last class I think somebody asked where exactly
we used the Boolean variables and Boolean values
39:00 - 39:30 so here all the conditional statements looping
statements Works based upon the Boolean values okay so if this condition returns true true means
what booing value if the condition return false false means what is also boing value okay based on
the value the statements will be executed now let us test this so first I'll say 10 20 30 so what we
are expecting now C is the largest number so when
39:30 - 40:00 I execute so you can say C is a largest number now
let's make uh a is 100 now when execute you will say a is the largest number now let's make B is
200 then it says b is a largest number okay so all all conditions are satisfied suppose instead of a
b and c I just want to print a number also along
40:00 - 40:30 with this a BC I want to just print number also
so that I can clearly know which number is largest number so how can we customize the statement so
a is the largest number whatever you have put in the double quotations it is as it is printing in
the console window right now if you want to print the number also the same number I just want to
print here simply what you can do concatenation let's plus a concatenation simple here also I
want to print the Value Plus B concatenation so
40:30 - 41:00 here also you can simply say plus C concatenation
right so when I execute it along with this it will also give the number right so guys understood
how to specify multiple conditions multiple if conditions along with multiple uh Expressions
so if condition can have one expression or if condition can also have multiple Expressions if
condition can have one expression or multiple
41:00 - 41:30 Expressions okay so like this we can practice
more number of examples by using uh if else conditions okay now let me show you one more
example now this time you guys can tell the output uh I'm just writing a simple program I can
say multiple statements so as I said before in
41:30 - 42:00 if Els condition we can also specify multiple
statements right single statement or multiple statements let me show you one more example
so here uh if true and here I'm printing one else here I'm printing two first of
all tell me this code is correct or
42:00 - 42:30 not this code is correct or not valid code or not say yes or no everyone it is
valid or not if true system P one else two can we put a Boolean value Direct if
condition without having any expression so I have not put any expression so just I'm
specifying a boing value can we put like
42:30 - 43:00 this why not we can easily put right ultimately
we need a Boolean value here right even if you say a greater than b or whatever what we are
expecting from this a Boolean value right this will return return it true or false so instead of
writing an expression I can directly write a boing value like this what's wrong in that right so
if condition is always accepting a Boolean value
43:00 - 43:30 and that Boolean value can be a direct value
or it can written by some expression okay so when I say if true then what is an output of
this statement so this is true then if block will execute right so when I execute this see
here you got one can we pass false here false
43:30 - 44:00 so if false then what will execute now if it
is a false else block will execute so when I run this this will return true you got my point
so what is my intention here is I just wanted to tell you instead of writing an expression we can
also Al write a a boan value because ultimately the expression will written true or false a boan
value will be written by the expression right in
44:00 - 44:30 all previous examples in if condition whatever
expression we have written all those expressions will return true or false a Bo value will be
return returned okay so if it is a true then if block will execute if it is a false else block
will execute I hope this is clear to everyone got my point here we are not comparing anything
actually here we are not comparing anything just
44:30 - 45:00 we are WR some Boolean value because the ultimate
goal of expression is when I compare something it will return true or false right instead of
comparison I'm directly say some Boolean value here it is valid because if condition always
accepting either true or false boan value it can be directly or through expression whatever
it is right you understood my context here in
45:00 - 45:30 if condition you can pass an expression or you
can pass a Boolean value directly that's what I'm saying okay for example let's say here I'm
saying 1 equal to 1 can we put like this 1 equal to 1 yes because this will also returns true
or false 1 equal to one true or false true if it is a true which one will execute if block will
execute so it will print one okay when I say one
45:30 - 46:00 equal to two the expression will return return
false so else block will execute else block will execute so what I'm saying here is you can put
either expression or you can directly put buan value But ultimately the if condition required
a Boolean value okay the if condition is always required provide a Boolean value if it is a
true if block will execute if it is a false
46:00 - 46:30 else block will execute okay that true or false
you can directly specify with the Boolean value or that comes through expression okay now let
me show you some more examples now this time you guys can tell the output of this program
okay so this is the one I'm commenting this at the time of practicing you can just uncomment
and you can try okay this is second example
46:30 - 47:00 now you guys can tell me the output
of this program so I can say if true okay and inside this I will put one more if condition okay so let me read the question
first when in If part you passed the Boolean value as a true okay then why it is passed
first block and return Valu as one because
47:00 - 47:30 if it is a true if it is a true obviously if
block will execute right so if the condition is true if block will execute in if block
what we have written here one only we have written that is the reason it is printing
one okay if a condition is true obviously the if block will execute that will return
one if the condition is false then else block
47:30 - 48:00 will execute then it will returns two
because we put one and two in the print statements okay yes now we can just
see here if true again inside the if condition I'll put one more if condition
this is called nested if else condition so the third one nested if Els condition the
third approach nested if nested if Els means what one if condition can have another if
condition multiple nested if Els condition
48:00 - 48:30 you can spfy so nested if Els I'm showing
here so if it is a true and enter into the block here I will again say true and then
here I'm printing some value so I can say ABC ABC lse system print and XY J okay now
after coming out of this if condition else
48:30 - 49:00 here I will say 1 2 3 this is my code
now tell me what is an output of this output ABC or XY Z or 1 2 3 which one what
is an output of this code so this piece of code okay so let us try to understand this
so first we'll start from here the condition
49:00 - 49:30 is true here if it is a true it will enter
into the block so what is the block of this if statement from here to here this is all
comes under if block first outer if block okay and this is comes under first if block now
if it is a true these statements should execute again if you come inside there is another if
condition so if it is a true then ABC will execute else part will ignore okay so if it
is true then ABC got executed so the output
49:30 - 50:00 of this code is what ABC so when I execute it
will return ABC because the outer if condition is true it come inside and then it this is also
true then the statement is called executed so rest of them will ignore okay suppose when I
say false here now tell me what is an output of this false so outer if condition is true
so it is entered into this block but inner if
50:00 - 50:30 condition is false if it is a false the else
part immediate else block will execute that is XY Z so this is the output of this program
XY Z okay now let us make this if condition false now tell me the output of this so if condition is false
means these statements will not be executed so this if block will ignore obviously
50:30 - 51:00 come to else block inside this we put
one 23 so it will execute obviously 1 2 3 okay so this is how we can also write
multiple if conditions and nested if else conditions one if condition can have
multiple if conditions one if condition can have a multiple if else conditions
so depends upon our requ requirement we can use these statements control statements
okay so we have seen only if a statement if
51:00 - 51:30 El a statement nested if nested if in the sense
one if condition can have another if condition multiple times you can specify now let me
show you one more example for multiple if conditions so example five so in this now I want to just print weak names
display weak names based on week number okay that
51:30 - 52:00 means I will provide some number when I say one
the program should display Sunday when I provide two the program should display Monday so when I
provide a number between 127 the corresponding week name should be displayed as an output
okay so how many weeks we have totally seven
52:00 - 52:30 weeks Sunday to Saturday right so all these seven
weeks we have to print based upon the week number so what is the input here week number is an input
okay so we need to check multiple conditions if the week number is one then print Monday if the
week number is two then print Tuesday if the week number three then print another so like this we
can write multiple conditions okay so let's try
52:30 - 53:00 to do this close and new class and print weak
names take this main method say finish so based upon the weak number I want to just print name
of the veker so what is an input here what is a variable you have to take a weak numers so I'll
take integer variable in week number let us start with one first now we need to check this weak
number we need to compare with uh multiple weak
53:00 - 53:30 numbers like 1 2 3 4 5 up to seven so what is the
first one if this weak number equal to one if the weak number equal to one what we should say this
is Sunday this is Sunday else one more condition
53:30 - 54:00 else if week number equal to two then we can say
m day one more condition else if the weak number weak number equal to three then you can say to St
so multiple conditions you can keep like this if Els if Els it FS like this so all the conditions
we can verify like this because total seven weeks
54:00 - 54:30 are there so four five six and finally what seven
obviously the last one uh is seven so that I can keep LF also lsf week number equal to 7 then I can
print certainty okay suppose if I provide invalid number other than 1 to 7 so weak number should
be between 1 to 7 so if the week number is other
54:30 - 55:00 than 1 to7 then what we should say invalid weak
number we should display invalid weak number so now what we need to do if we specify more number
of conditions if none of them are not satisfied finally else Block in this we can say invalid week
number because this else block will execute after completion of all the conditions if no condition
is not matching finally else block will execute
55:00 - 55:30 so this is invalid weak number you can print like
this so multiple conditions also we can verify by using IF else conditions like this okay now let
us test this code so initially say week number one so execute say Sunday so that means the
first condition itself is matched so thus this statement is got executed and as soon as this
condition is matched so rest of the conditions
55:30 - 56:00 will not be verified okay now let us make this
seven sorry here seven week number seven so it will verify all the conditions one by one and
finally one condition is got matched here week number seven so it is got printed Saturday
fine now let's say 10 here 10 so when I said 10 no condition is matching so finally else
block will execute so it will say number is
56:00 - 56:30 invalid weak number okay so this is how we can
Implement logic so we can also write multiple conditions multiple if else conditions depends
upon your requirement you can frame the logic okay so these are all conditional statements we
have seen if condition if else condition nested
56:30 - 57:00 if Els condition means if conditions can also
have another if conditions and finally switch case statement so when we have to use switch case
this is also comes under conditional statement but we need to understand when we have to use
switch case statement switch case statement uh we will prefer to use if we have a more number of
conditions for example let's look at this example
57:00 - 57:30 here we have almost seven conditions so how many
lines of code we have written here almost 40 plus almost 40 plus lines of code we have written to
verify the seven conditions so if you have more conditions like this seven conditions sometimes
you have a 10 condition 20 conditions if you have a more conditions like this instead of using IF
Els conditions better to go with a switch case statement why because switch case statement will
reduce the lot of code in switch case statement
57:30 - 58:00 it will also perform the same thing the objective
of same whatever the IFL condition is doing here same thing we can achieve by using switch case
statement but what is a major advantage of it is it will reduce the code it will reduce the code
so why we need to red uce the codee because if you are saying a developer is writing very good code
on what basis you will say if if the developer
58:00 - 58:30 is more efficient he will write a small thing
and do bigger task inefficient developers they will write a big code but do the small task so
unnecessarily we should not increase the size of the code we always try to reduce the code with
minimal code we should achieve the larger things so then only he's a efficient developer so instead
of writing more number of f conditions like this
58:30 - 59:00 more much much code we can try to reduce this code
by rating the switch case statement right so now let me show you how can we write switch case
statement and how to use switch case statement same program I will try to write a switch case
using switch case and then we will see how much of lines it will almost 50% of the code will
be reduced okay now we'll see the first syntax syntax switch
59:00 - 59:30 case so the syntax will be like this first we need
to start with the switch and here we don't specify the condition Cas okay we specify the variable
okay and inser this switch we will write one thing called case keyword Case Case is a keyword
here we specify the value of the variable okay so
59:30 - 60:00 if the variable value is equal to this one let's
say value one okay and then here we specify the statements okay and suppose if the variable
value is not equal to this one then another Case Case value equal to two then execute
another set of statements and suppose even this variable is not equal to this value two
then another Case Case value three and then
60:00 - 60:30 execute statements and if the variable value
is not equal to any of these value not matching with any of these values then finally we specify
default it is just like a else block so if none of the cases are not matching finally default
block statements will execute this is a switch case switch and case syntax so now let me show
you how can we use this uh with this switch case
60:30 - 61:00 commands so can we write a program without
declaring the variable using conditional statement yes you can write if you have such
requirement you can write you can directly put the expression because why variables are needed
you need to first understand that concept why we need to create a variable what is the importance
of variable to store the data right to store the
61:00 - 61:30 data or to maintain the data we have to create
a variables if you do not have variables what you want to achieve with the program if you do
not have any variables defined in your program what you want to achieve first of all you need to
clear about your goal right why you are writing the program what you want to achieve with this
program if you're clear about the goal objective then you will know exactly variables are required
or not okay variables are required or not so just
61:30 - 62:00 think logically guys why variables are required
to store the data and you have some data now you want to have some comparison then what you
will do definitely you will go with the control statements and if you don't want to compare
anything then don't go with the conditional statements if you have such requirement for
example I just create created two variables I just want to print the values of them do you
need control statements if else conditions you
62:00 - 62:30 you need them you don't need just you create a
variables and you're printing the data just by using print statement you can print values of
a b c you're not comparing anything so no need any control statements or if El conditions but
if you want to compare something if you want to do some operation based upon certain conditions
definitely you have to write a if else conditions you guys understood so variables definitely
we needed for almost in every program without
62:30 - 63:00 variable we don't write any program first of all
it doesn't make any sense without variable you don't want to achieve anything right if you
want to achieve something we have to write some program some logic some implementation
should be there if you just want to print a name I don't need any control statement what is
the main achievement for this right if you just simply write a system pintel and your name
what is the main objective of the program if
63:00 - 63:30 your objective is just printing the data you
don't need conditional statements but if you want to perform certain operations based upon
certain conditions comparison all these things you need to use conditional statements so you can
write program you can use conditional statement with variables and without variables also
but if I don't want to use variables there is no objective of that program see in the
previous example in multiple statements here
63:30 - 64:00 uh have you written any variables here
did I create any variables here in this program have you written any variables no
right I haven't used any variables still I have used conditional statements why because
I directly put the values instead of writing variables and storing the data I directly put
the values here so I have not used variables it depends on your requirement it keeps changing
okay so the input also we can pass through the
64:00 - 64:30 console window at the run time so that I will
show in the coming sessions because we want to know the scanner class so through the scanner
class we can take this input at the run time so once your program is got executed at the run
time you can provide the number randomly you can pass input that is possible okay that I will
cover in the coming sessions for now just follow this approach okay okay so now let us see how
can we write the same program using switch case
64:30 - 65:00 statement so if you want to achieve this we have
written almost 40 lines of gold 40 plus lines of gold when I use if else conditions right but if
you write the same program by using switch case statement we'll see how many lines of code is
got reduced fine so let me create another class switch case most important listen carefully
many times we prefer to use this switch case
65:00 - 65:30 statement okay just observe so I already told you
syntax so if the switch variable here we should not specify any condition okay we just specify
only variables and here we are comparing it so first we'll take a variable ENT weak number
let's take one now we need to write a switch
65:30 - 66:00 case statement how to start switch and here
we specify the variable what is the variable here weak number is a variable and inside this
switch we have to write a multiple cases so what is the first case here is case if the weak
number equal to one here value is what one if the weak number is one colon here we have
to put colon not curly Braes okay colon here
66:00 - 66:30 you can write whatever the statement you want to
execute so here I want to execute system. can say something and after completion of the statement
immediately you have to write one more thing called break break is basically called jumping
statement but here we have to use break command after executing the statement but I'll tell
you why we have to use this break statement
66:30 - 67:00 just hold on so this is one case suppose
if the weak number is not matching with one then another Case Case two here system
print say Monday again after the statement break bre okay like this I can write
multiple conditions I can write multiple
67:00 - 67:30 conditions okay so you can put this break
statement in the next line or in the same line no problem because the semicolon is representing
the end of the line this statement is got ended so after that you can put the statement in the
next line or you can keep in the same line no problem like this okay now we can put multiple
conditions case 1 2 3 4 up to seven conditions we have to specify so here we can write seven
conditions like this and after completion of
67:30 - 68:00 all seven cases finally if suppose none of the
cases are not matching then finally default here we have to say system P invalid weak number here
break is not required here break is not required okay so this is our program see how much size
it has got reduced almost 50% of the code is
68:00 - 68:30 got reduced if I use switch Cas statement okay
now let us first test this code and after that we'll see how it is got executed so week number
one means what week number one and case one is matching so obviously it will print Sunday okay
Sunday is going printed now let's make it as a seven so seven me seventh case matched
and Saturday got printed now let us
68:30 - 69:00 make [Music] 10 okay so 10 so let's try to
execute copy Java application now invalid weak so default is got executed if none of
the cases are not matching finally default is got executed fine it's perfectly working
fine now let us try to understand how this code is got executing and why we need this
break additional statement in every case so
69:00 - 69:30 normally switch case statements uh we work
based upon the case not condition actually so this week number equal to one then this
statement will execute if you not specified the break here for example if you're
not specified the break then what will happen Okay let me remove the break here okay and
we'll see what will happen let's say make it as
69:30 - 70:00 a one so first case is matching the statement
will execute right so when I execute this just observe what happens it is displayed two week
numbers Sunday is fine because the case one is got matched Sunday is got printed now immediately
what is printing Monday also it is printing so how it is happened because as soon as the statement
is got printed immediately it will execute the
70:00 - 70:30 next statement without checking any case without
checking this case by default the second statement will be executed okay so if you put this break
then what will happen after the statement is got executed we no need to execute the rest of the
statements it doesn't make any sense right at a time only one statement we want to execute so
when you specify break automatically this Brak
70:30 - 71:00 command will jump out from this switch command
this come out from entire block wherever The Brak is got executed that will break the condition
it will break the block it will come out from this block automatically same thing suppose if
the case one is not matching then it will go to case two and case two Monday is got displayed
immediately break it will come out from the Block if I don't specify break here then what
happens if break is not created here then what
71:00 - 71:30 happens so it is got printed
Sunday so let me just put two here then so it has got printed Monday and also it is
printed Tuesday because we haven't put we haven't put break here so now you understand what is the
importance of break here if I don't put break command it will automatically execute the next
command next statement without checking any case
71:30 - 72:00 so that is the reason as soon as your case is got
executed immediately we have to use break command this is mandator required for every case but
why we haven't specified break for default here we just specify only statement there is no break
can anyone guess why we haven't specify break for default why yes because after execution of
the statement there is no other statement to
72:00 - 72:30 be executed right this is the last statement
obviously it will automatically break after execution of this default statement it will
Anyway come out from the Block so break is not at all needed here but rest of the cases
break is mandator required so if I compared
72:30 - 73:00 this with our previous example same program same
objective we have achieved in two different ways by writing multiple if conditions by writing a
switch case statement and if you look at the size of The Code by using ifls conditions almost
we have written 40 plus lines and by using switch case statement we have just written 20 plus
lines almost 50% % of the code is got reduced so this is the main advantage of using switch case
statement so whenever you have a more number of
73:00 - 73:30 conditions to verify or compare try to use switch
case statement instead of using IF else condition statement so nothing wrong in this you can use
if else or switch case both are correct but which one will be used more efficiently when you compare
switch case statement will be preferred okay this is also another type of switch case statement so
these are all four different type of conditional
73:30 - 74:00 statements which we have discussed if if else
and N if else switch case these are all called conditional statement first category of control
statements so what is the use of conditional statements if you want to execute set of statement
or statements based upon certain condition we can go with conditional statements conditional
statements based upon the condition we can choose the particular block we want to execute
or not that we can decide based on the condition
74:00 - 74:30 then we can go with conditional statements and
we also have something called looping statements looping means the same set of statement we will
repeat multiple times reputation will be there and we have a while loop for Loop do while loop
multiple type of looping statements are there so in the next session we will discuss about looping
statements and then jumping statements okay and I got one question here is there a shortcut on the
keyboard what is the shortcut or copy duplicate uh
74:30 - 75:00 shortcut to copy or duplicate the code like you do
you can just copy paste control C and control V so actually some of the statements I already written
somewhere so I'm just copying from there okay so you have to write it or you can just copy paste
control C and call control V that's it nothing new okay so based on these topics I
will give you some assignments today
75:00 - 75:30 so you guys can try those assignments it
based on total today's topic conditional statements assignments okay so the first assignment so we
have seen how to find largest of three numbers right so by using multiple if else conditions
so you guys can try largest of two numbers very
75:30 - 76:00 small the largest of three numbers we WR multiple
condition but here the conditions will be reduced largest of two numbers and you can achieve this by
using two different ways using IF else conditions you can try also by using tary operator this is
very famous inter question tary operator do you guys remember what is tary operator yesterday
we have discussed it tary operator so by using
76:00 - 76:30 tary operator also we can achieve this solution
simple one single line we can achieve this you can also write if else conditions but instead
of writing if else conditions you can simply write one single statement ternary operator
to find largest of two numbers try this okay yesterday we have already discussed about tary
operator now the second example we have seen how to find largest of three numbers so you guys
can try smallest of three numbers okay smallest
76:30 - 77:00 of three numbers again you have to use if Els
conditions multiple condition ifs okay now the third example you have to print weak name name
okay so you have to print weak number based on
77:00 - 77:30 weak name exactly opposite we have here we have
seen we have taken weak number as an input and printed weak names right now what you have to
do you have to take weak name as an input and then print a weak name number here exactly you
have to do reverse okay so you have to take a weak name here as an input and here you have to
specify the weak number so how to replace this
77:30 - 78:00 so simple just I'm giving some clue you guys can
try so here we say in week number equal to 2 3 4 5 right but here you have to take a string
variable string week name equal to you can specify Sunday Monday or whatever you want this
is the input string we have to take input but how can we compare this in the switch case and if
you want to write a switch case you can write like this switch and here we name whatever the
variable we Define and how to write a cases here
78:00 - 78:30 case 1 2 3 4 no because this 1 2 3 4 is a values
actually weak numbers so here the weak names you have to write okay case because it is a string
we have to keep inside the double putting case Sunday like this okay case a Sunday then system.
and one and then break like this you have to write
78:30 - 79:00 you understood now so completely opposite so
here we Tak the week name and comparing with the week name in every case we have to write
a week name Sunday Monday Tuesday thday like this seven week names and you have to print week
number exactly opposite of this right so just you try this because we are keeping the strings right
because if it is a string we have to keep inside
79:00 - 79:30 the double quotations if it is a number we can
directly put the number try this so this is one assignment it is okay so so print week number based on
week name so here use switch
79:30 - 80:00 case okay so you guys can try these
three examples today and tomorrow once you discussed looping statements then I
will give you some more assignments right so we stop here for today's session
and tomorrow we'll continue it