Hello friends how are you, today in this blog i will teach you what is nested if statement, syntax of nested if , how nested if statement works and many programs using nested if in a very simple way.
Let's start
- It is used to test the condition.
- One if inside another if is called nested if.
class Easy { public static void main(String[] args) { int no=6; if(no>2)//true condition { if(no<3)//false condition { System.out.println("Hello1"); } System.out.println("Hello2"); } } } /* ### Output ### Hello2 */
Here we are going to make a program to find greater value in three number. If it is said that make this program using Nested if then make it using Nested if otherwise you can make this type of program using if or if else in a very simple way.
To make this program we take three variables to store numbers ,After taking user input we will apply condition on it and print result according to condition
import java.util.Scanner; class Easy { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a,b,c; System.out.println("Enter three number"); a=in.nextInt(); b=in.nextInt(); c=in.nextInt(); if(a>b) if(a>c) System.out.println(a+" is greater"); if(b>a) if(b>c) System.out.println(b+" is greater"); if(c>a) if(c>b) System.out.println(c+" is greater"); } } /* ### Output ### Enter three number 45 68 25 68 is greater */
Request:-If you found this post helpful then let me know by your comment and share it with your friend.
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.
If you have not subscribed my website then please subscribe my website.
Try to learn something new and teach something new to other.
Thanks.😊
0 Comments