java比较时间60分钟_第60分钟用java时钟打印

我不确定为什么会发生这种情况,但第60分钟会在第59分钟后变为小时后显示在结果中.

这是我的课程和主要课程:

public class Main {

public static void main(String[] args) {

BoundedCounter minutes = new BoundedCounter(59);

BoundedCounter hours = new BoundedCounter(23);

int i = 0;

while (i < 121) {

System.out.println(hours + ":" + minutes); // the current time printed

if (minutes.getValue() >= 59) {

hours.getValue();

i++;

}

}

}

// BoundedCounter

public class BoundedCounter {

private int value;

private int upperLimit;

public BoundedCounter(int upperLimit) {

this.upperLimit = upperLimit;

}

public void next() {

if (this.value >= this.upperLimit) {

this.value = 0;

} else {

this.value++;

}

}

public String toString() {

if (this.value < 10) {

return "" + 0 + value;

} else {

return "" + value;

}

}

public int getValue() {

if (this.value <= this.upperLimit) {

return this.value++;

} else {

return this.value = 0;

}

}

}

}

一些结果:

01:56

01:57

01:58

01:59

02:60

02:00

02:01

02:02

02:03

02:04

02:05

02:06

02:07

02:08

02:09

02:10

02:11

02:12

02:13

02:14

02:15

02:16

02:17

02:18

02:19

02:20

02:21

02:22

02:23

02:24

02:25

02:26

02:27

02:28

02:29

02:30

02:31

02:32

02:33

02:34

02:35

02:36

02:37

02:38

02:39

02:40

02:41

02:42

02:43

02:44

02:45

02:46

02:47

02:48

02:49

02:50

02:51

02:52

02:53

02:54

02:55

02:56

02:57

02:58

02:59

03:60

03:00

03:01

03:02

03:03

03:04

03:05

即2:60和3:60是意外输出

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值