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));
}
}