/* LeapYear.java * Ask the user for a year, and then tell if it is a leap year. * For a year to be a leap year, we need to make the following tests. * If the year is divisible by 100, must also be divisible by 400. * If not divisible by 100, must be divisible by 4. */ import java.util.Scanner; // for keyboard input public class LeapYear { public static void main(String [] args) { // Input System.out.printf("Please enter a year: "); Scanner sc = new Scanner(System.in); int year = sc.nextInt(); // Calculations and output if (year % 100 == 0 && year % 400 == 0 || year % 100 != 0 && year % 4 == 0) System.out.printf("Yes - that's a leap year!\n"); else System.out.printf("No - that's not a leap year.\n"); } }