[Solved] design a counter from 0-3 in java without %


Your C version does not print “0 1 2 0 1 2 …”. It prints “0 1 2 3 0 1 2 3 …” instead.

If you want a Java program that does what your C version really does:

public class Program {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(i & 3);
        }
    }
}

I’ll leave figuring out how it works up to you.

2

solved design a counter from 0-3 in java without %