Nested if else in Java programming language

Nested if else in Java programming language

In this article , we will discuss the Nested if else in Java programming language

Nested if statement

Nested if-else statement,which means use one if – else statement inside another if – else statement. Inside means if body or else body. One or more condition are evaluated by the nested if statement. 

At the nested if statement, when condition becomes true if part executed and print display statement and then enter next inner-if loop, when condition becomes false  else part executed and print else part display statement and then may be exit or terminated nested if loop 

syntex

Nested if else in Java

Syntax

Flow diagram nested if

flow chart



program 1

 

class ifcon2{
public static void main(String args[]){
int age=17;                                                   //variable assinment
int marks=73;                                             //variable assinment

if(age>16){                                                  //outer if loop -for check age
                                                                    //if boolean epression is true print this statement
                                                                   //-and enter inner if loop
System.out.println(“age enough check your marks”);
//if boolean epression is false go to it’s else part

if(marks>74){                                   //inner if loop -for check marks
                                                                   //if boolean epression is true print this statement
                                                                  //-and exit the program
System.out.println(“ok you enter course”);
//if boolean epression is false print it’s else part
}else
{System.out.println(“not enough marks”);
}
}else
{System.out.println(“not enough age”);
//at the outer if loop,if boolean expression is false
                                                             //only print this statement 
}
}
}

in the progran, outer if loop condition is true but inner if condition is false so display above output

program 2
class ifcon2{
public static void main(String args[]){
int age=12;
int marks=75;
int rank=30;
if(age>11){
if(marks>74){
if(rank>25){
System.out.println(“ok you enter course and get scholer”);
} else
{
System.out.println(“ok you enter course and not get scholer”);
                       }
}else
{
                 System.out.println(“ok you enter course and not get scholer”);
                 }
}else
      {System.out.println(“not enough age”);
}
}
}
Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.