package day02_1;
import java.util.Scanner;
/**
* 任务:
* 让用户输入年月
* 打印该月所有日期
* 作者:gaowen
* 版本V:1.0
* 时间:2018年3月29日22:22:14
* @author huagaowen
*有待完善:没有做到对齐星期
*/
public class Calendar_Sheet
{
public static void main(String[] args)//程序入口
{
Scanner scan = new Scanner(System.in);
System.out.println("请输入年份");
int year = scan.nextInt();
System.out.println("请输入月份");
int month = scan.nextInt();
boolean years;//润年开关
System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期天\t");
//开始判断用户输入的年份是否为闰年
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
years = true;//如果是闰年则为true
}
else
{
years = false;//否则为false
}
//判断该月是否是1,3,5,7,8,10,12如果是则打印31天
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
for(int i = 1; i <= 31; i++)
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
//如果是4,6,9,11则打印30天
else if( month == 4 || month == 6 || month == 9 || month == 11)
{
for(int i = 1; i <= 30; i++)//打印30天
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
else if(month == 2 && years)//打印闰年2月
{
for(int i = 1; i <= 29; i++)//打印29天
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
else if(month == 2 && years == false)//打印平年2月
{
for(int i = 1; i <= 28; i++)//打印28天
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
}
}
import java.util.Scanner;
/**
* 任务:
* 让用户输入年月
* 打印该月所有日期
* 作者:gaowen
* 版本V:1.0
* 时间:2018年3月29日22:22:14
* @author huagaowen
*有待完善:没有做到对齐星期
*/
public class Calendar_Sheet
{
public static void main(String[] args)//程序入口
{
Scanner scan = new Scanner(System.in);
System.out.println("请输入年份");
int year = scan.nextInt();
System.out.println("请输入月份");
int month = scan.nextInt();
boolean years;//润年开关
System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期天\t");
//开始判断用户输入的年份是否为闰年
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
years = true;//如果是闰年则为true
}
else
{
years = false;//否则为false
}
//判断该月是否是1,3,5,7,8,10,12如果是则打印31天
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
for(int i = 1; i <= 31; i++)
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
//如果是4,6,9,11则打印30天
else if( month == 4 || month == 6 || month == 9 || month == 11)
{
for(int i = 1; i <= 30; i++)//打印30天
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
else if(month == 2 && years)//打印闰年2月
{
for(int i = 1; i <= 29; i++)//打印29天
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
else if(month == 2 && years == false)//打印平年2月
{
for(int i = 1; i <= 28; i++)//打印28天
{
System.out.print(i+"\t");
if(i % 7 == 0)//一行打印7天日期,满7天换行
{
System.out.println();//打印换行
}
}
}
}
}