这个Java程序,month为什么要减1呢?
来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/28 07:19:15
这个Java程序,month为什么要减1呢?
import java.util.*;
public class PersonClass{
private int No;
private String name;
private boolean sex;
private Date birthday;
public PersonClass(){}
public PersonClass(int No,String name,boolean sex,int year,int month,int day){
this.No=No;
this.name=new String(name);
this.sex=sex;
this.birthday=new Date(year,month-1,day);
}
public void setNo(int No){this.No=No;}
public void setName(String name){this.name=new String(name);}
public void setSex(boolean sex){this.sex=sex;}
public void setBirthday(int year,int month,int day){
this.birthday=new Date(year,month-1,day);
}
public int getNo(){return No;}
public String getName(){return name;}
public boolean getSex(){return sex;}
public Date getBirthday(){return birthday;}
public boolean equals(Object otherObject){
if(this==otherObject){
return true;
}
if(otherObject==null){
return false;
}
if(getClass()!=otherObject.getClass()){
return false;
}
PersonClass other=(PersonClass)otherObject;
if(No==other.No){
return true;
}else{
return false;
}
}
public String toString(){
return"\nNo:"+No+"\nName:"+name+"\nSex:"+sex+"\nBirthday:"+String.format("%tF", birthday);
}
}
import java.util.*;
public class PersonClass{
private int No;
private String name;
private boolean sex;
private Date birthday;
public PersonClass(){}
public PersonClass(int No,String name,boolean sex,int year,int month,int day){
this.No=No;
this.name=new String(name);
this.sex=sex;
this.birthday=new Date(year,month-1,day);
}
public void setNo(int No){this.No=No;}
public void setName(String name){this.name=new String(name);}
public void setSex(boolean sex){this.sex=sex;}
public void setBirthday(int year,int month,int day){
this.birthday=new Date(year,month-1,day);
}
public int getNo(){return No;}
public String getName(){return name;}
public boolean getSex(){return sex;}
public Date getBirthday(){return birthday;}
public boolean equals(Object otherObject){
if(this==otherObject){
return true;
}
if(otherObject==null){
return false;
}
if(getClass()!=otherObject.getClass()){
return false;
}
PersonClass other=(PersonClass)otherObject;
if(No==other.No){
return true;
}else{
return false;
}
}
public String toString(){
return"\nNo:"+No+"\nName:"+name+"\nSex:"+sex+"\nBirthday:"+String.format("%tF", birthday);
}
}
因为JDK的月份表示范围是0~11,分别表示1月至12月.
而用户习惯表示的月份往往是从1开始至12之间.
为了将用户习惯的月份表示法转换到JDK固定的表示法,故将用户表示的月份数减1,以得到JDK表示的月份数.
而用户习惯表示的月份往往是从1开始至12之间.
为了将用户习惯的月份表示法转换到JDK固定的表示法,故将用户表示的月份数减1,以得到JDK表示的月份数.
这个Java程序,month为什么要减1呢?
JAVA:int month = n.get(Calendar.MONTH)+1;为何要加1?
这个程序为什么运行不了呢.
这个画星星的java程序,为什么每次只显示一个星星?
java中this.month=month>0?month:1;什么意思
简单的java程序,谁能解释下第1,5,9行啊,为什么要用grade,第9行的用法,
java中我要实现读取在1到100之间的整数,然后计算每个数出现的次数,我的程序为什么不对,
为什么是java.io.IOException呢
java中bs开发和cs开发相结合的程序,为什么要这样结合呢?是bs中有cs无法作到的,还是cs有bs无法做到的?
java 程序阅读 Parent
java问题:this.setContentPane(pane);是什么意思?pane为什么要放在括号里面呢?
这段程序的RAND_MAX为什么要加1.0呢?