从按制台接收用户的输入的出生日期,输出从用户出生的那一年到今年为止,每年的生日当月的日历,生日当天标*号,并统计这么多年用户生日当天为一周中每一天的百分比(即生日为周一的在这么多年中占的百分比,生日为周二的在这么多年中占的百分比。。。。。)
import java.util.Scanner;
public class Birthday {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int Year=input.nextInt(),
Month=input.nextInt(),
Day=input.nextInt();
int i,m=Month;
double sum[]=new double[7];
for(i=0;i<7;i++)
sum[i]=0;
if(Month==1||Month==2)
m+=12;
for(i=Year;i<2022;i++){
System.out.println(i);
System.out.println("周日\t周一\t周二\t周三\t周四\t周五\t周六");
int First_Day=(i%100) + (i%100) / 4 + (i/100) / 4 - 2*(i/100) + 26* (m + 1 ) / 10 +700;
First_Day%=7;
/*System.out.println(First_Day);*/
int F=First_Day;
while(F>0) {
System.out.print("\t");
F--;
}
int j=First_Day,k=30,l=1;
if(Month==2) {
if(Year % 4 == 0 && Year % 100 != 0 || Year % 400 == 0)
k = 29;
else
k = 28;
}
else if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12)
k++;
while(l<=k){
if(j==7){
j=0;
System.out.print("\n");
}
System.out.print(l);
if(l==Day) {
System.out.print("*");
sum[j]++;
}
System.out.print("\t");
l++;
j++;
}
System.out.print("\n");
}
for(i=0;i<7;i++) {
sum[i]/=(2022-Year);
System.out.print("星期"+(i+1)+": ");
System.out.printf("%.3f\n",sum[i]);
}
}
}