标签:字符 [] next for ring 日历表 万年历 输入 rgs
import java.util.Scanner; public class Year { public static void main(String[] args){ int a,o,x,oo,oa,oc,os,ab,ooq,oaq,v; do{ System.out.println("\n***********************"); System.out.println("1.判断某年是否是闰年\n2.判断某年某月有多少天\n3.计算某年某月某日距离1990年1月1日的总天数\n4.输出某年某月的日历\n0.退出"); System.out.println("请选择您的需求\n"); Scanner sas=new Scanner(System.in); //从键盘上输入一个字符 os=sas.nextInt(); switch(os){ case 1:System.out.println("请输入年份"); Scanner scb=new Scanner(System.in); //从键盘上输入一个字符 ab=scb.nextInt(); if(judgeYear(ab)==1) System.out.println("该年是闰年"); else System.out.println("该年不是闰年"); break; case 2: System.out.println("请输入年份"); Scanner sc=new Scanner(System.in); //从键盘上输入一个字符 a=sc.nextInt(); System.out.println("请输入月份"); Scanner sa=new Scanner(System.in); //从键盘上输入一个字符 o=sa.nextInt(); x=days(a,o); System.out.println(a+"年"+o+"月有"+x+"天"); break; case 3: System.out.println("请输入年份"); Scanner saa=new Scanner(System.in); oo=saa.nextInt(); System.out.println("请输入月份"); Scanner sam=new Scanner(System.in); oa=sam.nextInt(); System.out.println("请输入日份"); Scanner san=new Scanner(System.in); //从键盘上输入一个字符 oc=san.nextInt(); v=dayfrom1990(oo,oa,oc); System.out.println(v); break; case 4: System.out.println("请输入年份"); Scanner saaa=new Scanner(System.in); ooq=saaa.nextInt(); System.out.println("请输入月份"); Scanner samq=new Scanner(System.in); oaq=samq.nextInt(); print(ooq,oaq); break; case 0:break;} }while(os!=0); } public static int judgeYear(int b){ //判断是否是闰年 int c; if(b%100==0){ c=b%400; } else c=b%4; if(c==0){ return 1;} else{ return 0;} } public static int days(int m,int n){ //判断某年某月有几天 int p; p=judgeYear(m); if(n==1|n==3|n==5|n==7|n==8|n==10|n==12) return 31; else if(n==4|n==6|n==9|n==10) return 30; else { if(p==1) return 29; else return 28; } } public static int dayfrom1990(int q,int j,int u){ int r=0; if(q==1990){ for(int i=1; i<= j-1;i++) r+=days(1990,i); r+=u; return r; } else{ for(int i=1990; i<= q-1;i++){ if(judgeYear(i)==1) r+=361; else r+=360; } for(int ii=1; ii<= j-1;ii++) r+=days(q,ii); r+=u; return r; } } public static void print(int as,int bs){ int xq,z=0; System.out.println("-----------"+as+"年"+bs+"月日历表------------"); xq=dayfrom1990(as,bs,1)%7+1; //计算出该年该月第一天是星期几 System.out.println("一\t二\t三\t四\t五\t六\t日"); for(int k=1;k<xq;k++){ System.out.print("\t" ); z++; } for(int i=1;i<=days(as,bs);i++){ System.out.print(i+"\t"); z++; if(z%7==0){ System.out.print("\n");} } } }
标签:字符 [] next for ring 日历表 万年历 输入 rgs
原文地址:http://www.cnblogs.com/qwe1219/p/7577478.html