0% found this document useful (0 votes)
23 views3 pages

Nested If

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Nested If

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

4)nested if :

===========
When we have if else statement inside if statement and when we have if else
statement inside else statement
then we should go for nexted if statement.

Syntax :

if(){

if(){

}else{

}else{

if(){

}else{

Example :

package decisionMakingStatements;

public class NestedIfStatement {

public static void main(String[] args) {

int a=20;
int b=30;
int c=10;

if(a>b) {

if(a>c) {
System.out.println(a);
}else {
System.out.println(c);
}
}else {
if(b>c) {
System.out.println(b);
}else {
System.out.println(c);
}
}
}
}

Example :
package decisionMakingStatements;

public class NestedIfStatement {

public static void main(String[] args) {

int a=30;
int b=20;
int c=10;

if(a>b) {

if(a>c) {
System.out.println(a);
}else {
System.out.println(c);
}
}else {
if(b>c) {
System.out.println(b);
}else {
System.out.println(c);
}
}
}
}

Example :

package decisionMakingStatements;

public class NestedIfStatement {

public static void main(String[] args) {

int a=10;
int b=20;
int c=30;

if(a>b) {

if(a>c) {
System.out.println(a);
}else {
System.out.println(c);
}
}else {
if(b>c) {
System.out.println(b);
}else {
System.out.println(c);
}
}
}
}

Example :
package decisionMakingStatements;

import java.util.Scanner;

public class NestedIfStatement {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


System.out.println("Enter First no");
int a = sc.nextInt();
System.out.println("Enter Second no");
int b = sc.nextInt();
System.out.println("Enter Third no");
int c = sc.nextInt();
if (a > b) {

if (a > c) {
System.out.println(a);
} else {
System.out.println(c);
}
} else {
if (b > c) {
System.out.println(b);
} else {
System.out.println(c);
}
}
}
}

You might also like