Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Java Programming

Tutorial: Boxes - Modulus.

 
The modulus operator % gives the remainder when one number is divided by another.

1. Horizontal Stripes


Big

i % 2 gives 0 if i is even and 1 if i is odd.

Change the code so that the stripes are vertical.

Vertical line

2. Spaced Stripes


Big

Change the code so that the stripes are at 0, 4 and 8.

Spaced stripes

3. Grid


Big

The grid shown has red if either i or j is an even number.

Grid

4. Chess board


Big

Produce the checker board pattern shown.

Grid
Hint:

5. Trailing diagonal stripes


Big

Diagonal stripes.

Grid
Hint:

6. Diagonal grid


Big

Now we are just playing, stop this and move onto something less silly!

Diagonal grid.

Grid
Hint: