只需if
在for循环中添加语句,该语句将在每n行输出之后输出新行(我相信这是您想要的,而不是在n次迭代之后)。假设您要每3行换一行伪代码:
int newLine = 3;
int multiplicator = 1;
for(int i = 0; i< names.length; i++){
if( newLine == i){
// print extra line after every 3rd output
field.append("\n");
newLine = 3; //to reset variable to the correct delimiter on each subsequent n-th iteration
multiplicator++;
newLine = newLine * multiplicator;
}
field.append(names[i] + "\n")
// print regular value on normal line during every iteration
}