LeapYear project

code:-


import java.util.Scanner;

// save this java file with LeapYear.java
public class LeapYear {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            System.out.print("Enter any year ");
            int n = sc.nextInt();
            if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0){
                System.out.println("This is leap Year");
            }
            else {
                System.out.println("Its not a leap year");
            }
           
             System.out.print("Enter the year from where you want to search: ");
            int m=sc.nextInt();
            System.out.print("Till the year you want to search ");
            int k=sc.nextInt();
            if(k==m){
            System.out.print("Enter proper year !");
            }

            System.out.println("Enter 1 number if you want only leap year list");
            System.out.println("Enter 2 number if you want only normal year list");
            System.out.println("Enter 3 number if you want list of all leap and normal years");
            System.out.print("Enter 1/2/3 : ");
            int num = sc.nextInt();
            if(num==1){
                if(k>m){
                    for(int i=m;i<=k;i++){
                       if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
                       System.out.println(i+" is a leap year");
                       }
                   }
               }
       
               else if (k<m){
                   for(int i=m;i>=k;i--){
                       if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
                       System.out.println(i+" is a leap year");
                       }
                   }
               }
            }
            else if(num==2){
                if(k>m){
                    for(int i=m;i<=k;i++){
                       if (i % 4 != 0 || i % 100 == 0 && i % 400 != 0){
                       System.out.println(i+" is not a leap year");
                       }
                   }
               }
       
               else if (k<m){
                   for(int i=m;i>=k;i--){
                       if (i % 4 != 0 || i % 100 == 0 && i % 400 != 0){
                       System.out.println(i+" is not a leap year");
                       }
                   }
               }
            }
            else if(num==3){
                if(k>m){
                    for(int i=m;i<=k;i++){
                       if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
                       System.out.println(i+" is a leap year");
                       }
                       else{
                           System.out.println(i+" is not a leap year");
                       }
                   }
               }
       
               else if (k<m){
                   for(int i=m;i>=k;i--){
                       if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
                       System.out.println(i+" is a leap year");
                       }
                       else{
                           System.out.println(i+" is not a leap year");
                       }
                   }
               }
            }
               
    }
}

Output:-


  • case-1(list of only leap year):-

list of leap year



  • case-2(list of year except leap year ):-

list of year except leap year 



  • case-3(list of both leap year & normal years):-

list of both leap & normal year



Comments