Computer Science, asked by shalini683, 1 year ago

Write a program to input YEAR and check whether it is : (a) a leap year (b) a century leap year (c) a century year but not a leap year

Sample input: 2000

Sample output: It is a century leap year

Using scanner class method




It is a java program


Please answer it correctly

I will mark you as brainlist

Please answer it very fast

Answers

Answered by Anonymous
20

CODE IN JAVA


import java.util.*;

class Leap_year

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the year");

int n=sc.nextInt();

if(n%100==0)

{

if(n%400==0)

{

System.out.println(n+" is a century leap year");

}

else

{

System.out.println(n+" is a century year");

}

}

else if(n%4==0)

{

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

}

else

{

System.out.println(n+" is not a leap year");

}

}

}



LOGIC :


⇒ I am taking the year as input .

⇒ Then I am checking whether the year is divisible by 100 or not !

⇒  If it is divisible by 100 , then I check whether it is divisible by 400 or not !

⇒ If it is not divisible by 100 , it has to be divisible by 4 in order to become a leap year.

⇒ If all conditions are false , then it has to be a non-leap year.



OUTPUT :

Sample input : 1900

Sample output : 1900 is a century year .

Sample input : 4000

Sample output : 4000 is a century leap year .


Thank you ^______________^


shalini683: sample input is 2000 na
Anonymous: whatever u take...if sample input is 2000 then output = century leap year.
Answered by sanjaykumar1810
10
import
java.util.*;

import
java.lang.*;

import
java.io.*;

 

class LeapYear   {

    static int year; static Scanner inp;

   public static void main (String[] args)
throws java.lang.Exception {

       inp = new Scanner(System.in);

       year =
Integer.parseInt(inp.next());

       if (year % 4==0) {

          if (year
% 400==0)     System.out.println(year +
"is a century leap year");

         else if
(year % 100==0) System.out.println(year + " is not a leap year");

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

     }

     else     System.out.println(year+ " is not a
leap year");

  }

}

mark my answer!!!
Similar questions