Is there a nicer way to do the count I’m doing below?
I’m sure this must be possible with modulus or something. I’m looking for someway to manipulate i instead of using the extra variable x. (to beautify this).
Here is the long way round:
int MAX = 4;
int x = 0;
for (int i = 0; i < 50; i++) {
System.out.print(x);
if(x++; == MAX)
x = 0;
}
Expected outcome:
// 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 .. etc
1 Answer