【问题标题】:to limit the limit count variable to fixed value将限制计数变量限制为固定值
【发布时间】:2022-01-19 09:53:52
【问题描述】:

我想根据限制计数中的值执行一些代码,但我想将其值限制为最大 20000。 例如,如果通过的限制计数为 50000,则运行代码三次,值为 20000,20000,10000 如果限制计数为 10000,则按原样运行它

【问题讨论】:

  • 是如何计算这三个值的?在代码中做同样的事情。

标签: java loops while-loop


【解决方案1】:

我猜,你需要这样的东西:

int limit = 50000;
int maxLimit = 20000;

while (limit > 0) {
  callYourCode(Math.min(limit, maxLimit));
  limit -= maxLimit;
}

【讨论】:

  • 感谢它的工作 int count=50000; while(count>=20000) { System.out.println("将 20000 传递给方法");计数=计数-20000; } if(count==20000) { System.out.println("runnig with 20000"); } else { System.out.println("运行"+count); } 这是最后的代码
猜你喜欢
  • 1970-01-01
  • 2011-08-10
  • 2022-11-03
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-09
  • 1970-01-01
相关资源
最近更新 更多