Is a Year a Leap Year?
This program determines if the first argument passed to it is a leap year, and prints the result.
A year is a leap year if it is divisible by 4, unless it is divisible by 100. However, years divisible by 400 are leap years.
The program internally uses a method that throws one of two exceptions: one if the year is a leap year, and one if it isn't. Because these exception classes don't do anything different from the built-in Exception class, they don't need to override any methods; they can simply be declared and used.
To convert the command-line parameter from a string to a number, the program uses the static method parseLong() ...
Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.