Compare commits
No commits in common. "f9788e9a7d36b201e86939f107aa9e29ec4e5219" and "1e3aa2f3b3cfa52607a11e6bca1f13e0b993a031" have entirely different histories.
f9788e9a7d
...
1e3aa2f3b3
@ -1,56 +0,0 @@
|
|||||||
/** Class that determines whether or not a year is a leap year.
|
|
||||||
* @author YOUR NAME HERE
|
|
||||||
*/
|
|
||||||
public class LeapYear {
|
|
||||||
|
|
||||||
/** Calls isLeapYear to print correct statement.
|
|
||||||
* @param year to be analyzed
|
|
||||||
*/
|
|
||||||
private static void checkLeapYear(int year) {
|
|
||||||
if (isLeapYear(year)) {
|
|
||||||
System.out.printf("%d is a leap year.\n", year);
|
|
||||||
} else {
|
|
||||||
System.out.printf("%d is not a leap year.\n", year);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method check if year is leap
|
|
||||||
*/
|
|
||||||
public static boolean isLeapYear(int year) {
|
|
||||||
if (year % 400 == 0) {
|
|
||||||
return true;
|
|
||||||
} else if (year % 100 != 0 && year % 4 == 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void countDaysInYear(int year) {
|
|
||||||
if (isLeapYear(year)) {
|
|
||||||
System.out.println("366 days");
|
|
||||||
} else {
|
|
||||||
System.out.println("365 days");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Must be provided an integer as a command line argument ARGS. */
|
|
||||||
public static void main(String[] args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
System.out.println("Please enter command line arguments.");
|
|
||||||
System.out.println("e.g. java Year 2000");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
|
||||||
try {
|
|
||||||
int year = Integer.parseInt(args[i]);
|
|
||||||
checkLeapYear(year);
|
|
||||||
countDaysInYear(year);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
System.out.printf("%s is not a valid number.\n", args[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user