标题:新人学 Java,作业是做个日历,但是每个月的星期六都是空格,求解决
只看楼主
游骑兵hai
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-10-29
结帖率:0
已结贴  问题点数:20 回复次数:1 
新人学 Java,作业是做个日历,但是每个月的星期六都是空格,求解决
import java.util.Scanner;
public class menology {
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        System.out.println("请用户输入年份");
        int year=in.nextInt();
        System.out.println("请用户输入月份");
        int month=in.nextInt();
        int sum=0;
        for(int i=1900;i<year;i++){
            if(year%4==0&&year%100!=0||year%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;
        int wekday=sum%7;
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        for(int i=1;i<wekday;i++){
            System.out.print("\t");
        }
        if(month==2){
            if(year%4==0&&year%100!=0||year%400==0){
                for(int i=1;i<=29;i++){
                    if(sum%7==6){
                        System.out.print(i+"\n");
                    }else{
                        System.out.print(i+"\t");
                    }
                    sum++;
                }
            }else{
                for(int i=1;i<=28;i++){
                    if(sum%7==6){
                        System.out.print(i+"\n");
                    }else{
                        System.out.print(i+"\t");
                    }
                    sum++;
                }
            }
        }else if(month==4||month==6||month==9||month==11){
            for(int i=1;i<=30;i++){
                if(sum%7==6){
                    System.out.print(i+"\n");
                }else{
                    System.out.print(i+"\t");
                }
                sum++;
            }
        }else{
            for(int i=1;i<=31;i++){
                if(sum%7==6){
                    System.out.print(i+"\n");
                }else{
                    System.out.print(i+"\t");
                }
                sum++;
            }
        }
    }
}
搜索更多相关主题的帖子: public import 星期六 Java 日历 
2014-10-29 21:12
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
得分:20 
http://blog.

上面的例子能够正常运行,参考一下
Debug或者在关键的计算结果的地方pringln一下吧
2014-11-01 11:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-437867-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.196004 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved