我有这段代码:
/* For loop to count 50 days */
for (int n = 1; n <= 50; n++) {
int solve = 0;
solve = solve++;
item_1.removeDailyDemand();
if ( n % 5 == 0){
}
if (solve == 5){
item_1.isReOrderPoint();
}
System.out.print(n + "\t");
System.out.println (item_1.getQuantityInStock() + "\t");
玩了很多年,对Java来说很新。我只是希望它增加&#34;解决&#34;因为它&#34; n&#34;同时运行for循环。
大部分时间都在尝试,没有结果!
谢谢
答案 0 :(得分:1)
替换:
/* For loop to count 50 days */
for (int n = 1; n <= 50; n++) {
int solve = 0;
solve = solve++;
人:
/* For loop to count 50 days */
int solve = 0;
for (int n = 1; n <= 50; n++) {
solve++;
在每次迭代中,您将solve
变量重置为0。
并且solve = solve++
没用,因为首先复制solve变量然后递增它。与solve++
答案 1 :(得分:1)
每次循环内部都声明求解为零:
/* For loop to count 50 days */
int solve = 0;
for (int n = 1; n <= 50; n++) {
solve += 1;
item_1.removeDailyDemand();
// same as your previous code
}
或者在类似的行上你可以使用:
/* For loop to count 50 days */
int solve = 0;
for (int n = 1; n <= 50; n++, solve++) {