I am new to programming and I am writing code for this assignment in school in which I need to have the user enter a month (first three letters), and then a year (taking in to account of leap years). This is what I have done:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int Year = input.nextInt();
System.out.print("Enter a month (first three letters with the first"
+ " letter uppercase): ");
String Month = input.next();
String ThirtyOne = "Jan" + "Mar" + "May" + "Jul" + "Aug" + "Oct" + "Dec";
String DaysThirtyOne = ThirtyOne.substring(21) + "31";
String Thirty = "Apr" + "Jun" + "Sep" + "Nov";
String DaysThirty = Thirty.substring(12) + "30";
String TwentyEight = "Feb";
String DaysTwentyEight = TwentyEight.substring(3) + "28";
if (ThirtyOne.contains(Month)) {
System.out.println(Month + " " + Year + " has " + DaysThirtyOne
+ " days in it.");
}
if (Thirty.contains(Month)) {
System.out.println(Month + " " + Year + " has " + DaysThirty
+ " days in it.");
}
if (TwentyEight.contains(Month)) {
System.out.println(Month + " " + Year + " has " + DaysTwentyEight
+ " days in it.");
}
My code probably doesn't look very professional and I'm sure many of you would have gone about what I've completed so far a different way but what I am having trouble with now is taking the Year input from the top and using that in an algorithm to determine if it is a leap year. I keep getting an error when I try to do it because the year is an int and NetBeans says that it can't convert int to boolean. I don't want to make another class to convert it though. What do I do to get that input from the user and use it to determine if it is a leap year? I already know that the year needs to be divisible by 4, 100, and 400.