Nested if statement in Java.

Nested if statement in Java

 
  • 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
*/
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
*/
Next Post Previous Post
No Comment
Add Comment
comment url