Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* * This program uses a boolean method isLeapYear to determine if the given parameter number is a year * on which a leap year

/*

* This program uses a boolean method isLeapYear to determine if the given parameter number is a year

* on which a leap year occurs

*/

public class IsLeapYear

{

public static void main(String[] args)

{

System.out.println("Year 500 is a Leap Year: " + isLeapYear(500) + " Expected: false") ;

System.out.println("Year 2020 is a Leap Year: " + isLeapYear(2020) + " Expected: true") ;

System.out.println("Year 1000 is a Leap Year: " + isLeapYear(1000) + " Expected: false") ;

System.out.println("Year 100 is a Leap Year: " + isLeapYear(100) + " Expected: false") ;

System.out.println("Year 1724 is a Leap Year: " + isLeapYear(1724) + " Expected: true") ;

}

/**

Determines if input is a leap year.

@param year current year (integer)

@return true if year is a leap year, false otherwise

*/

//-----------Start below here. To do: approximate lines of code = 6

// Write a static method isLeapYear. This method returns a boolean (true of false). It takes one parameter: an integer value - the year

// A year is a leap year if it is exactly divisible by 400 (i.e. remainder is 0)

// If it is not divisible by 400 then a year is also a leap year if it is exactly divisible by 4 AND it is NOT exactly divisible by 100

// Hint: use the modulus operator % to check if exactly divisible

the commented out portion is my code:

[ /*public static boolean isLeapYear(int year){

if(year % 4 == 0)

{

if (year % 400 == 0)

IsLeapYear = true;

}

if (year % 100 == 0)

IsLeapYear = false;

else

IsLeapYear = true; */

} ]

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

Let X ~ N(, 2). Find the pdf of Y = eX.

Answered: 1 week ago