在java中执行一定数量的循环后执行操作
在到达数组列表中特定数量的循环(例如10)后,我必须在控制台中显示一条消息,然后显示一条关于数组列表中剩余项的消息 数组列表包含从在java中执行一定数量的循环后执行操作,java,loops,iterator,Java,Loops,Iterator,在到达数组列表中特定数量的循环(例如10)后,我必须在控制台中显示一条消息,然后显示一条关于数组列表中剩余项的消息 数组列表包含从a到z的所有小写字母 现在,在一个计数器中,我使用了MOD来检查这一点 for (int i = 0; i > arrayList.length; i++) { // If loop is not at 0 and MOD with 10 is == 0 then it means we have to show message if(i !=
a
到z
的所有小写字母
现在,在一个计数器中,我使用了MOD
来检查这一点
for (int i = 0; i > arrayList.length; i++)
{
// If loop is not at 0 and MOD with 10 is == 0 then it means we have to show message
if(i != 0 and i % 10 == 0)
{
// Show console
}
}
我如何处理剩余的项目?由于字母表中有26个字母,它将在前20个字母上打印,但我不确定如何处理后6个字母。信息也应该印在上面。它应该显示控制台消息3次,而不是2次。因为列表中有26次,所以可以更均匀地按最后一个值进行分解
for (int i = 0; i < arrayList.length; i++) {
// do something
// every ~1/3rd completed
if(i % 9 == 8 || i == arrayList.length - 1) {
// Show console
}
}
for(int i=0;i
简单的更改是再次检查是否到达阵列末端
for (int i = 0; i < arrayList.length; i++)
{
// If loop is not at 0 and MOD with 10 is == 0 then it means we have to show message
if((i != 0 and i % 10 == 0) || (i == arrayList.length - 1))
{ // This executes on 10 , 20, and end of array.
// Show console
}
}
for(int i=0;i
您只需添加一个附加条件,检查消息是否显示三次。如果消息未显示三次,则第三条消息将显示在数组的最后一个元素上
这可能适用于元素大于20个的数组
int count = 0;
for (int i = 0; i > arrayList.length; i++)
{
// If loop is not at 0 and MOD with 10 is == 0 then it means we have to show message
if((i != 0 and i % 10 == 0) or (count<3 and i = arrayList.length-1))
{
count++;
// Show console
}
}
int count=0;
对于(int i=0;i>arrayList.length;i++)
{
//若循环不在0,而MOD with 10为==0,则表示我们必须显示消息
如果((i!=0和i%10==0)或(count问题是,10的限制可能不同,也可能会有额外的字母:(有时是5,有时是6:(.我想把和额外的if等放在循环中谢谢我会试试:)哦,是的!:)我想这就是答案了!谢谢各位大师!