Java,第二次作业——显示台历

题目:超难

( 显示日历)编写程序,提示用户输入年份和代表该年第一天是星期几的数字,然后在
控制台上显示该年的日历表。例如,如果用户输入年份 2013 和代表 2013 年 1 月 1 日为
星期二的 2, 程序应该显示该年每个月的日历,如下所示
在这里插入图片描述

public static void f15()
	{
		int i,j,month_total_days,month=1;
		System.out.print("year  :  ");
		int year=input.nextInt();
		System.out.print("The first day of this year is  :  ");
		int weekday=input.nextInt();
		
	
			
			for (month=1;month<=12;month++)
			{
				switch(month)
				{
					case 1:
				  System.out.println("\t\t\t"+"January"+" "+year);
				  break;
				  case 2:
				  System.out.println("\t\t\t"+"Februry"+" "+year);break;
				  case 3:
				  System.out.println("\t\t\t"+"March"+" "+year);break;
				  case 4:
				  System.out.println("\t\t\t"+"April"+" "+year);break;
				  case 5:
				  System.out.println("\t\t\t"+"May"+" "+year);break;
				
				  case 6:
				    System.out.println("\t\t\t"+"June"+" "+year);break;
				 
				  case 7:
				   System.out.println("\t\t\t"+"July"+" "+year);break;
				  
				  case 8:
				  System.out.println("\t\t\t"+"August"+" "+year);break;
				 
				  case 9:
				   System.out.println("\t\t\t"+"September"+" "+year);break;
				 
				  case 10:
				   System.out.println("\t\t\t"+"October"+" "+year);break;
				 
				  case 11:
				  System.out.println("\t\t\t"+"November"+" "+year);break;
				  case 12:
				  System.out.println("\t\t\t"+"December"+year);break;
				  default: break;
				}
			
		    System.out.println("———————————————————————————————————");
		     System.out.println("Sun"+"\t"+"Mon"+"\t"+"Tue"+"\t"+"Wed"+"\t"+"Thu"+"\t"+"Fri"+"\t"+"Sat");
	
			
				 if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
					month_total_days=31;
				else if(month==2)
				{
						if(((year % 4 ==0 && year % 100!=0)||(year %400 ==0)))
							//如果某年可以被4整除而不能被100整除,或者可以被400整除,那么这一年就是闰年
						month_total_days=29;
							else 
							month_total_days=28;
				}
				else
					month_total_days=30;
				
	
			//	weekday=(weekday+flag)%7;
				
			 
				//printf(month_total_days,flag,weekday);
				weekday=(printf(month_total_days,weekday))%7;
				
			}
	}
					public static int printf(int month_total_days,int weekday)
	{
		int flag=0,i;
		  for( i=0;i<weekday%7;i++)
				{
					System.out.print("\t");//该循环用于输出第一行的空格个数,  //星期几,就有几个\t
					flag+=1;//计数是否满7个数,每满7个位置就换行
				}
	
		for( int j=1;j<=month_total_days;j++)
		{	
		   System.out.print(j);
		   //System.out.print("\t");
			flag++;
			if(flag%7==0){
			System.out.println();
			}
			
		else
			System.out.print("\t");
		
		}
		
		System.out.println();
		System.out.println();
		System.out.println();
		return flag;
		
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值