public Time(int hour, int minute, int second) {}
1.首先判断合理性:
hour:不能<0,≥60
minute:不能<0,≥60
second:不能<0,≥60
2.逻辑:
推断seconds以后的时分秒
这里应为while循坏;当seconds特别大,须要执行屡次
例如:ide
while (other.second >= 60) {// other.second -= 60;//61-60=1 other.minute += 1; if (other.minute >= 60) {//不会>60,通常是等于60,由于不可能传入一个≥60的值 other.minute = 0;//置0 other.hour += 1;//小时加1 if (other.hour >= 24) {//通常不会>24 ,等于24即置0 other.hour = 0; } } }
second+=seconds
当second超过最大值,minute+=1
当minute超过最大值,hour+=1code
推断seconds以前的时分秒;
1.当seconds<second
second-=seconds
很好处理,时分不变
2.当seconds>second
second=seconds-second
second=60-second;
minute-=1
当minute≤0
hour-=1it
这时,时分秒都更新了class