LeapYear - public static void main(String args int year...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // LeapYear.java Author: Lewis/Loftus // // Solution to Programming Project 3.2 // // Reads an integer value representing a year. Determines if the year // is a leap year //******************************************************************** / import java.util.Scanner; i public class LeapYear { //----------------------------------------------------------------- // Reads an integer value representing a year. Determines if the year // is a leap year //-----------------------------------------------------------------
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public static void main (String args) { int year; boolean leap = false; Scanner sc = new Scanner(System.in); System.out.print("Enter a year : "); year = sc.nextInt(); if (year < 1582) System.out.println("ERROR year not valid in the Gregorian calendar"); else { if (year % 4 == 0) // divisible by 4 { leap = true; if ((year % 100 == 0) && (year % 400 != 0)) { leap = false; } } if (leap) System.out.println(year + " is a leap year"); else System.out.println(year + " is not a leap year"); } } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online