this code outputs a sequence of 5, 10, 15.. but if i change the value at i%5 to i%6 it will wtill output 5 but in a sequence of +6 like 5, 11, 17, 23, 29 ...
my problem is how come it started with 5 as the output and why, since 5 is not intialized to int i anywhere in the code and why does it follow that sequence, even when i change the value of i%5 to i%4, it still follows the same sequence in i%6. why?
from k&b
page 6
import java.lang.Runnable;
class Wombat implements Runnable {
private int i;
private int x;
public synchronized void run() {
if (i%4 != 0) { i++; }
for(int x=0; x<5; x++, i++)
{ if (x > 1) Thread.yield(); }
System.out.print(i + " ");
}
public static void main(
String[] args) {
Wombat n = new Wombat();
for(int x=100; x>0; --x) { new
Thread(n).start(); }
} }