JAVA programs

Program to check leap year

In this program we see how to check particular year is leap year or not using the else- if ladder statement. We can check multiple condition using else if ladder. Following program demonstrate use of else-if ladder.

Program

class ElseifDemo

{

    public static void main(String args[])

    {

        int year=2000;

        if(year%100==0 && year%400==0)

        System.out.println("2000 is a leap year");

        else if(year%4==0)

            System.out.println("2000 is a leap year");

        else

            System.out.println("2000 is not leap year");

    }

}

When Run The Program Following Output:

2000 is a leap year

Description

Using else – if ladder We can check multiple condition using else if ladder.

Syntax of else-if ladder

 

If (condition)

   Statement to execute;

else if(condition)

   Statement to execute;

.

.

.

else

   Statement to execute if all above condition false;

Releted Programs

© 2017 codewmAll rights reserved.