示例代码
int count=0;
while(true)
{
if(count>3)
System.out.print("value"+count);
count=count+1;
}
所需输出:
Value 0
Value 1
Value 2
Value 0
Value 1
Value 2
只要控制在 while 循环内流动,它就应该重复打印上面的值。如何更改上面的代码?
最佳答案
使用模数。
int count = 0;
while(true) {
System.out.println("Value " + count);
count = ++count % 3;
}
关于java - 以循环方式打印值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19112709/