import java.util.Scanner;
class CalendarMain
{
//主函数入口
public static void main(String[] args)
{
System.out.println("*****请输入日期(格式如: 2011-01)*****");
Scanner sc = new Scanner(System.in);
String ym = sc.next();
//截取字符串
String[] yearMonth = ym.split("-");
//将字符串转化成整型
int year = Integer.parseInt(yearMonth [0]);
int month = Integer.parseInt(yearMonth [1]);
Year.fun(year);
Month.fun(month,year);
}
}
//获取闰年个数
class Year
{
//多少个闰年
static int leapYear = 0;
public static void fun(int year){
if(year > 1990 && year <10000){
while(year >= 1990){
if(year % 4 == 0 && year % 100 != 0 || (year % 400 ==0 )){
leapYear ++;
}
year --;
}
}else{
System.out.println("请输入查询的年份大于或等于1990年!");
}
}
}
//获取一个月多少天和总天数
class Month
{
public static void fun(int month,int year){
int monthDay = 0;
Year y = new Year();
int days = y.leapYear + (year - 1990)*365;
if(month > 0 && month <=12){
for(int i = 1;i <= month;i++){
if(i < 8 && i != 2){
days += i % 2 == 1 ? 31 :30;
monthDay = i % 2 == 1 ? 31 :30;
}
if(i > 7){
days += i % 2 == 1 ? 30 :31;
monthDay = i % 2 == 1 ? 30 :31;
}
if(i == 2){
if(year % 4 == 0 && year % 100 != 0 || (year % 400 ==0 )){
days += 28;
monthDay = 29;
}else{
days += 28;
monthDay = 28;
}
}
}
Show.mothed(days,monthDay);
}else{
System.out.println("请输入正确的月份!");
}
}
}
//显示日历
class Show
{
public static void mothed(int days, int monthDay){
//加一表示从星期一开始
int week = (days - monthDay) % 7 + 1;
System.out.println("\n周日"+"\t周一"+"\t周二"+"\t周三"+"\t周四"+"\t周五"+"\t周六");
for (int i = 1;i <= monthDay + week ;i++ )
{
if(i <= week){
System.out.print(" "+"*"+"\t");
}else{
if((i-week) < 10){
System.out.print(" "+(i-week)+"\t");
}else{
System.out.print((i-week)+"\t");
}
}
if(i%7 == 0){
System.out.print("\n");
}
}
}
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

Dreamweaver Mac版
视觉化网页开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。