第五章第二十八题(显示每月第一天是星期几)(Display the first days of each month)
**5.28(显示每月第一天是星期几)编写程序,提示用户输入年份和代表该年第一天是星期几的数字,然后在控制台上显示该年各个月份的第一天是星期几。例如,如果用户输入的年份是2013和代表2013年1月1日为星期二的2,程序应该显示如下输出: January 1, 2013 is Tuesday … December 1, 2013 is Sunday **5.28 (Display the first days of each month) Write a program that prompts the user to enter the year and first day of the year, then displays the first day of each month in the year. For example, if the user entered the year 2013, and 2 for Tuesday, January 1, 2013, your program should display the following output: January 1, 2013 is Tuesday … December 1, 2013 is Sunday
参考代码:
package chapter05;import java.util.Scanner;publicclassCode_28{
publicstaticvoidmain(String[] args){
int year, theFirstDay, totalDay =0;
Scanner inputScanner =newScanner(System.in);
System.out.print("Enter the year: ");
year = inputScanner.nextInt();
System.out.print("Enter the first day of the year: ");
theFirstDay = inputScanner.nextInt();for(int i =1; i <=12; i++){
switch(i){
case1:
System<