分享

关于日历

 陈陈陈clj 2017-01-17

package com.imooc;

import java.util.Scanner;

public class Demo {

 public static void main(String[] args) {
  System.out.println("***欢迎来到德莱联盟***");
  int years=0;
  int month=0;
  int days=0;
  int totaldays=0;
  Scanner scanner=new Scanner(System.in);
  System.out.println("请输入年份!");
  years =scanner.nextInt();
     System.out.println("请输入月份!");
     month=scanner.nextInt();
 
     if(years%400==0||(years%100==0&&years%4==0)){
      System.out.println(years+"是闰年!");
     }
     else{
      System.out.println(years+"非闰年!");
     }
    
     for(int i=1900;i<years;i++){
      if(i%400==0||(i%100==0&&i%4==0)){
      totaldays+=366;
      }
      else{
       totaldays+=365;
      }
      }
   for(int i=1;i<=month;i++){
     if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
      {
      days=31;
     }
     else if(month==2){
      if(years%400==0||(years%100==0&&years%4==0)){
       days=29;
      }
      else{
       days=28;
      }
     }
     else if(month==4||month==6||month==9||month==11){
      days=30;
     }
    
     else{
      System.out.println("你所输入的月份不正确!");
     }
     if(i!=month){
     totaldays+=days;
     }
   }
     System.out.println(years+"年"+month+"月数对应的天数为"+days);
  
     //判断星期几
 int beforedays=0;
 beforedays=1+totaldays%7;
 if(beforedays==7){
  beforedays=0;
 }
 System.out.println("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
 for(int i=0;i<beforedays;i++){
  System.out.print("\t");
 }
 for(int i=1;i<=days;i++){
  System.out.print(i+" \t");
  if((i+beforedays)%7==0){
   System.out.println( );
  }
 }
 
 } 
}
这个源代码运行有点小问题,希望读者可以自己解决!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约