java之万年历显示,质数,水仙花数显示

万年历

以1900年1月1日为初始,这一天为星期一

//求出距离1900年1月1日一共多少天
		Scanner s=new Scanner(System.in);
		
		System.out.println("请输入年份");
		int year=s.nextInt();
		System.out.println("请输入月份");
		int months=s.nextInt();
		int count=0;
//算年
		for(int i=1900;i<year;i++) 
		{
			if((i%4==0&&i%100!=0)||i%400==0) 
			{
				count+=366;
			}
			else 
			{
				count+=365;
			}
		}
		//算月
		
		for(int i=1;i<13;i++)
		{
			if(i==2) 
			{
				if((year%4==0&&year%100!=0)||year%400==0)
				{
					count+=28;
				}
				else 
				{
					count+=29;
				}
			}
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) {
				count+=31;
			}						
			else
			{
				count+=30;
			}			
		}
		//blank为空格数
		int blank=1+count%7;
		if(blank==7) {
			blank=0;
		}
		
		System.out.println(count);
		
		System.out.print("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
		for(int i=0;i<blank;i++) 
		{
			System.out.print("\t");
		}
		int currentMonth;
		if(months==2) 
		{
			if((year%4==0&&year%100!=0)||year%400==0)
			{
				currentMonth=28;
			}
			else 
			{
				currentMonth=29;
			}
		}
		if(months==1||months==3||months==5||months==7||months==8||months==10||months==12) {
			currentMonth=31;
		}						
		else
		{
			currentMonth=30;
		}			
		for(int i=1;i<=currentMonth;i++)
		{
			System.out.print(i+"\t");
			if((i+blank)%7==0)
			{
				System.out.print("\n");
			}
			
		}
		
	}

质数

//质数
//		int count=0;
//		for(int i=2;i<=100;i++) {
//			boolean b=true;
//			for(int j=2;j<i;j++) {
//				if(i%j==0) {
//					b=false;
//					break;
//				}
//			}
//			if(b) {
//				count=count+i;
//			}			
//		}
//		System.out.println(count);

水仙花数

            for(int i=100;i<999;i++) {
//			int a=i%10;
//			int b=i/10%10;
//			int c=i/100;
//			if(i==a*a*a+b*b*b+c*c*c) {
//				System.out.println(i);
//			}
//		}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值