JavaBase02

package unit01;

public class Class04 {
	public static void main(String[] args) {
		int year=2016;
		Class04 s=new Class04();
		if(s.isLeapYear(year)){
			System.out.println(year+"是闰年");
		}else{
			System.out.println(year+"不是闰年");
		}
		for(int month=0;month<12;month++){
			s.showYear(year, month);
		}
	}
	public boolean isLeapYear(int year){
		if(year%4==0&&year%100!=0)
			return true;
		else return false;
	}
	public void showYear(int year,int month){
		int []monthDays=new int[12];
		monthDays[0]=31;
		monthDays[1]=isLeapYear(year) ? 29:28;
		monthDays[2]=31;
		monthDays[3]=30;
		monthDays[4]=31;
		monthDays[5]=30;
		monthDays[6]=31;
		monthDays[7]=31;
		monthDays[8]=30;
		monthDays[9]=31;
		monthDays[10]=30;
		monthDays[11]=31;
		System.out.println(year+"年"+(month+1)+"月");
		System.out.println("------------------------------------------------------");
		int days =monthDays[month];
		for(int i=0;i<days;i++){
			System.out.printf("\t%d",i+1);
			if((i+1)%7==0)
				System.out.println();
		}
		System.out.println();
		System.out.println("--------------------------------------------------------");
		}
}

实现的功能:(1)输出生日是星期几(2)计算看完电影是几点

package unit01;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Class05 {
	public static void main(String[] args) {
		Date date=new Date("1996/08/19");//调用Date类实例化对象名date
		SimpleDateFormat s=new SimpleDateFormat("E");//调用SimpleDateFormat类实例化
		String str=s.format(date);//定义一个对象指向星期
		System.out.println(str);
		Date data=new Date("2018/10/11 18:30");//调用Date类实例化对象名data
		long time=data.getTime();//获取总的时间毫秒
		data.setTime(time+146*60*1000);//加上看电影的时间
		s=new SimpleDateFormat("HH:mm");//转换成小时:分钟
		System.out.println(s.format(data));
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值