简体   繁体   English

java替换数组的元素

[英]java replacing elements of an array

["

The main question will be at the bottom.<\/i>主要问题将在底部。<\/b> From the text file below, lets say the first integer is a, second is b, and third is c and so forth.<\/i>从下面的文本文件中,假设第一个整数是 a,第二个是 b,第三个是 c,依此类推。<\/b> the program takes a,b and c, parses them, puts them into myCalculations method which returns a string with two integers.<\/i>该程序获取 a、b 和 c,解析它们,将它们放入 myCalculations 方法中,该方法返回一个带有两个整数的字符串。<\/b> The string is parsed, a and b are replaced the integers in said returned string, then the next iteration of the loop will take the new values for a and b, and integer d.<\/i>解析字符串,将 a 和 b 替换为所述返回字符串中的整数,然后循环的下一次迭代将采用 a 和 b 的新值以及整数 d。<\/b> This will continue until the end where a and b are printed to the user.<\/i>这将一直持续到将 a 和 b 打印给用户的末尾。<\/b><\/p>

The input from a two text files is as follows:<\/i>来自两个文本文件的输入如下:<\/b><\/p>

The format of the text file is as follows:<\/i>文本文件的格式如下:<\/b><\/p>

200 345 
36
45
36
21

I honestly haven't understood what the whole exercise should do, but the code You enlighted could be wrong due to the indexes You use: those indexes are always 0 and 1, even if cycles are performed through some other indexes.老实说,我不明白整个练习应该做什么,但是由于您使用的索引,您启发的代码可能是错误的:这些索引始终是 0 和 1,即使循环是通过其他一些索引执行的。 At the end of the second code snippet, the f-for modify the array "newResults" at the increasing index "f", but that array is read always at the same index: 0 and then 1. So, if "f" gets higher values than "1" then the "aliveSoldiers"'s elements are left unchanged.在第二个代码片段的末尾,f-for 在增加的索引“f”处修改数组“newResults”,但该数组总是在相同的索引处读取:0 和 1。所以,如果“f”得到高于“1”的值,则“aliveSoldiers”的元素保持不变。

In particular, aliveSoldiers is modified only on the first two indexes, the other indexes are not used at all.特别是,aliveSoldiers 仅在前两个索引上进行了修改,其他索引根本没有使用。

Do you need a stack-like or queue-like behaviour?您需要类似堆栈或类似队列的行为吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM