LeapYear2 - { int year; boolean leap = false; Scanner sc =...

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

View Full Document Right Arrow Icon
//******************************************************************** // LeapYear2.java Author: Lewis/Loftus // // Solution to Programming Project 3.3 // // Determines if a year is a leap year. //******************************************************************** / import java.util.Scanner; i public class LeapYear2 { //----------------------------------------------------------------- // Reads an integer value representing a year. Determines if the year // is a leap year. Prompts the user to enter another year or quit. //----------------------------------------------------------------- public static void main (String[] args)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int year; boolean leap = false; Scanner sc = new Scanner(System.in); do { System.out.print("\nEnter a year (0 to quit): "); year = sc.nextInt(); if (year != 0) { 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"); } } leap = false; } while (year !=0); } }...
View Full Document

Ask a homework question - tutors are online