#显示每月第一天是星期几 #显示日历
作者:互联网
显示每月第一天是星期几
输入年份
import java.util.*;
import javax.swing.*;
class Main {
public static void main (String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter year: (e.g., 2008): ");
int yearNotChange = input.nextInt();
String yearString = yearNotChange + "";
int month = 0;
int oneDayOfMonth = 1;
for(int i = 1; i <= 12; i++){
int year = yearNotChange;
month = i;
if(month == 1 || month == 2){
month += 12;
year -= 1;
}
int dayOfWeek = (oneDayOfMonth + (int)((26 * (month + 1)) / 10)
+ (year % 100) + (int)((year % 100) / 4)
+ (int)((int)(year / 100) / 4)
+ 5 * (int)(year / 100)) % 7;
String dayOfWeekString = "";
switch(dayOfWeek){
case 0:
dayOfWeekString = "Saturday";
break;
case 1:
dayOfWeekString = "Sunday";
break;
case 2:
dayOfWeekString = "Monday";
break;
case 3:
dayOfWeekString = "Tuesday";
break;
case 4:
dayOfWeekString = "Wednesday";
break;
case 5:
dayOfWeekString = "Thursday";
break;
case 6:
dayOfWeekString = "Friday";
break;
}
String monthString = "";
switch(i){
case 1:
monthString = "January";
break;
case 2:
monthString = "February";
break;
case 3:
monthString = "March";
break;
case 4:
monthString = "April";
break;
case 5:
monthString = "May";
break;
case 6:
monthString = "June";
break;
case 7:
monthString = "July";
break;
case 8:
monthString = "Augest";
break;
case 9:
monthString = "September";
break;
case 10:
monthString = "October";
break;
case 11:
monthString = "November";
break;
case 12:
monthString = "December";
break;
}
System.out.println(monthString + " 1, " + yearString +" is " + dayOfWeekString);
}
}
}
显示日历
标签:显示,String,第一天,int,日历,System,yearNotChange,import,input 来源: https://www.cnblogs.com/doudou-20123/p/16313223.html