
If you have already register Login here.
Nested if Statement in java
if(Condition 1) {
   // Executes when the Condition 1 is true
   if(Condition 2) {
      // Executes when the Condition 2 is true
   }
}
if (x == 0)
{
   System.out.println("x is zero");
}
else
{
   if (x > 0)
   {
      System.out.println("x is positive");
   }
   else
   {
      System.out.println("x is negative");
   }
}
Leap Years are any year that can be evenly divided by 4. A year that is evenly divisible by 100 is a leap year only if it is also evenly divisible by 400.
import java.util.Scanner;  //Needed for Scanner object
public class Getleapyear
{
   public static void main(String[] args)
   {
      int year;    // holds a year
      // Create a Scanner object for keyboard input.
      Scanner scanNumber= new Scanner(System.in);
      // Get the year.
      System.out.print("Enter a year : ");
      year = scanNumber.nextInt();
      // Determine whether the year is leap year.
      if (year % 4 == 0)
      {
         if (year % 100 == 0)
         {
            if (year % 400 == 0)
            {
               System.out.println("A leap year");
            }
            else
            {
               System.out.println("Not a leap year");
            }
         }
         else
         {
            System.out.println("A leap year");
         }
      }
      else
      {
         System.out.println("Not a leap year");
      }
   }
}Output 1Enter a year : 2012
 A leap year
Output  2Enter a year : 1992
 A leap year
Output 3Enter a year : 2018
 Not a leap year
Output 4Enter a year : 2017
 Not a leap year
© 2025 Easy To Learning. All Rights Reserved | Design by Easy To Learning
