java中this.month=month>0?month:1;什么意思

来源:学生作业帮助网 编辑:六六作业网 时间:2024/06/08 19:14:45
java中this.month=month>0?month:1;什么意思java中this.month=month>0?month:1;什么意思java中this.month=month>0?mont

java中this.month=month>0?month:1;什么意思
java中this.month=month>0?month:1;什么意思

java中this.month=month>0?month:1;什么意思
这是条件语句.boolean?a:b 如果boolean为true,则执行a语句,否则执行b语句.
this.month=month>0?month:1;此语句的意思是:如果month变量为正数,this对象的month变量赋值为month变量,否则赋值为1.