注册 登录
编程论坛 JAVA论坛

万年历结果问题

仍去寻酒 发布于 2016-08-23 22:23, 1868 次点击
package xiti;
import java.util.Scanner;

public class caleldar {

    public static void main(String[] args) {
        int sum=0;
        Scanner s=new Scanner(System.in);
        System.out.println("请输入年份");
        int year=s.nextInt();
        System.out.println("请输入月份");
        int month=s.nextInt();

        for(int i=1900;i<year;i++){
            if(i%4==0&&i%100!=0||i%400==0){
                sum+=366;
            }else{
                sum+=365;
            }
        }
        
        for(int i=1;i<month;i++){
            if(i==2){
                if(year%4==0&&year%100!=0||year%400==0){
                    sum+=29;
                }else{sum+=28;}
            }else if(i==4||i==6||i==9||i==11){
                sum+=30;
            }else{sum+=31;}
            
            }sum+=1;
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        for(int i=1;i<sum%7;i++){
            System.out.print("\t");
        }   
        
            for(int i=1;i<=30;i++){
            if(sum%7==6){System.out.print(i+"\n");}
            else {System.out.print(i+"\t");}
            sum++;
        }    if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
            System.out.print("31");
        }

    }

}
输入2012年 1月 还是对的 但是你看看2016年 8月 就不对了。。求解答
3 回复
#2
仍去寻酒2016-08-23 22:24
请输入年份
2012
请输入月份
1
日    一    二    三    四    五    六
1    2    3    4    5    6    7
8    9    10    11    12    13    14
15    16    17    18    19    20    21
22    23    24    25    26    27    28
29    30    31
请输入年份
2016
请输入月份
8
日    一    二    三    四    五    六
1    2    3    4    5    6
7    8    9    10    11    12    13
14    15    16    17    18    19    20
21    22    23    24    25    26    27
28    29    30    31

[此贴子已经被作者于2016-8-24 04:22编辑过]

#3
仍去寻酒2016-08-24 04:26
额 咳咳,我自己找到错误了。。
在下面加多少“/t”的时候出错了:for(int i=1;i<sum%7;i++)这里应该是for(int i=0;i<sum%7;i++),少了一个“/t”的输出。
#4
libin25198852016-08-31 11:39
嗯嗯
1