Basic HTML version of Foils prepared 13 July 98

Foil 25 Modulo Arithmetic

From Java Academy II:Advanced Java NPAC/ECS Java Academy -- February to April 98. by Tom Scavo


On a checkerboard, every other square is filled
To accomplish this, we use the modulus operator (%) on the sum of the loop variables: if ( ( i + j ) % 2 == 0 ) { square.draw( g ); } else { square.fill( g ); }
Basically, "x % 2 == 0" checks if x is even



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998