================================================== ============
QUESTION:
(Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2012, the program should display that February 2012 had 29 days. If the user entered month 3 and year 2015, the program should display that March 2015 had 31 days. Use switch statement.
Here is a sample run:
Enter a month in the year (e.g., 1 for Jan): 2
Enter a year: 2020
February 2020 has 29 days
================================================== =============
I hope i am posting this in the right forum.
I got everything right except the days/month/year thing, as in Feb 2019 has 28 days and feb 2020 has 29 days. how can i do this ?
================================================== ==============
My code.
import java.util.Scanner;
public class DaysInMonths {
public static void main (String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a month in the year: ");
int month = input.nextInt();
System.out.println("Enter a year: ");
int year = input.nextInt();
switch(month) {
case 1:
System.out.println("January " + year + " has 30 days");
break;
case 2:
System.out.println("February " + year + " has 29 days");
break;
case 3:
System.out.println("March " + year + " has 30 days");
break;
case 4:
System.out.println("April " + year + " has 31 days");
break;
case 5:
System.out.println("May " + year + " has 30 days");
break;
case 6:
System.out.println("June " + year + " has 31 days");
break;
case 7:
System.out.println("July " + year + " has 30 days");
break;
case 8:
System.out.println("August " + year + " has 31 days");
break;
case 9:
System.out.println("September " + year + " has 30 days");
break;
case 10:
System.out.println("October " + year + " has 31 days");
break;
case 11:
System.out.println("November " + year + " has 30 days");
break;
case 12:
System.out.println("December " + year + " has 31 days");
break;
default:
System.out.println("Month not valid!");
break;
}
}
}
As you can see i just placed the days in a string but i just don't know how to add the calendar thing ( still learning here )
Thank you!!