Skip to main content

Posts

Showing posts with the label 6. Write a Java program to check whether a year is leap year or not.

ads1

6. Write a Java program to check whether a year is leap year or not.

    6. Write a Java program to check whether a year is leap year or not.   Static Solution  :- class leap {     public static void main(String args[])     {     int no1=2010;         if(no1 % 4 == 0)         {             System.out.println("It is Leap Year :- "+no1);         }            else     {         System.out.println("It is not a Leap Year :- "+no1);     }     } }   Output :-    Dynamic   Solution :- import java.util.*; class leap   {     public static void main(String args[])     {         int no1;          Scanner out = new Scanner(System.in);         System.out.println("Enter the Year :- ");         no1 = out.nextInt();         if(no1 % 4 == 0)         {              System.out.println("It is Leap Year :- "+no1);         }         else         {              System.out.println("It is Not a Leap Year :- "+no1);            }     } }   Output :-

ads2