只需
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}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)