Table of Contents
In this article , we will discuss the Nested if else in Java programming language
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
Flow diagram nested if
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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.