Nested if with Example in Java
In this class, We discuss Nested if with Example in Java.
The reader should have prior knowledge of if elseif else statements. Click Here.
The "If" statement is written inside the "If" statement. We call it nested if.
With an example, we understand it better.
Example:
if(condition)
{
if(condition)
{
}
else
{
}
}
else
{
if(condition)
{
}
else
{
}
}
In the above example, the condition of the first if statement is true. Then the "if" statement inside is executed.
Below example helps the reader to understand the situation where a nested if statement helps.
Example:
Write a program to divide students into batches based on the below table conditions.
Student marks for five subjects will be provided.
1) Maths
2) English
3) Physics
4) Social
5) Chemistry
Total marks gt 400 and maths gt 90 he belongs to Bathch A.
Total marks gt 400 and maths lt 90 he belongs to Bathch B.
Total marks gt= 400 and maths gt 90. He belongs to Batch C.
Total marks lt= 400 and maths lt 90 he belongs to Bathch A.
The below diagram shows the complete code.
The first two conditions are the same total marks greater than 400.
The second conditions are different in the first two lines in the table.
So we go with the nested if condition here.
Code:
Link for playlists:
/ @learningmonkey
Link for our website: https://learningmonkey.in
Follow us on Facebook @ / learningmonkey
Follow us on Instagram @ / learningmonkey1
Follow us on Twitter @ / _learningmonkey
Mail us @ learningmonkey01@gmail.com
In questa pagina del sito puoi guardare il video online Nested if with Example in Java || Lesson 18 || Java Programming || Learning Monkey || della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Learning Monkey 10 maggio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 122 volte e gli è piaciuto 2 spettatori. Buona visione!