java输入日期计算天数_Java输入日期得到天数

package com.huangtao.sxt;

public class YearMonthDay {

private int year;

private int month;

private int day;

//使用一个静态数组变量

public static int[] months={31,28,31,30,31,30,31,31,30,31,30,31};

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public int getMonth() {

return month;

}

public void setMonth(int month) {

this.month = month;

}

public int getDay() {

return day;

}

public void setDay(int day) {

this.day = day;

}

public YearMonthDay(){

}

public YearMonthDay(int year, int month, int day) {

super();

this.year = year;

this.month = month;

this.day = day;

}

/*

* 判断是否是闰年

* 4年一闰,百年不闰,400年又闰

*/

private void isRunYear(){

if((this.year%4==0&&this.year%100!=0)||this.year%400==0){

//闰年

months[1]=29;

}else{

//平年

months[1]=28;

}

}

/*

* 天数计算

*/

public int totleDays(){

isRunYear();

int totle = 0;

for(int i=0;i

totle = totle+months[i];

}

totle =totle+this.day;

return totle;

}

/*

* 判断用户输入是否存在

*/

public void isExits(){

if(month<0||month>12){

System.out.println("月份错误");

System.exit(0);

}

if(day<0||day>31){

System.out.println("日期错误");

System.exit(0);

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值