Explore Westonci.ca, the premier Q&A site that helps you find precise answers to your questions, no matter the topic. Connect with professionals ready to provide precise answers to your questions on our comprehensive Q&A platform. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.
Sagot :
Answer:
Explanation:
The following code is written in Java and uses Switch statements to connect the month to the correct number of days. It uses the year value to calculate the number of days only for February since it is the only month that actually changes. Finally, the number of days is printed to the screen.
import java.util.Scanner;
public class NumDaysPerezGabriel {
public static void main(String args[]) {
int totalDays = 0;
Scanner in = new Scanner(System.in);
System.out.println("Enter number for month (Ex: 01 for January or 02 for February): ");
int month = in.nextInt();
System.out.println("Enter 4 digit number for year: ");
int year = in.nextInt();
switch (month) {
case 1:
totalDays = 31;
break;
case 2:
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
totalDays = 29;
} else {
totalDays = 28;
}
break;
case 3:
totalDays = 31;
break;
case 4:
totalDays = 30;
break;
case 5:
totalDays = 31;
break;
case 6:
totalDays = 30;
break;
case 7:
totalDays = 31;
break;
case 8:
totalDays = 31;
break;
case 9:
totalDays = 30;
break;
case 10:
totalDays = 31;
break;
case 11:
totalDays = 30;
break;
case 12:
totalDays = 31;
}
System.out.println("There are a total of " + totalDays + " in that month for the year " + year);
}
}
Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.