L04 - Iteration Lab - Part 1 - Nested For Loops
We can determine if a number is even or odd by checking the remainder after dividing the number by 2:
if (number % 2 == 0)
System.out.println(number + " is even");
else
System.out.println(number + " is odd");
- Create a class named
Patterns
that uses this technique with two nested for loops to reproduce the pattern below. The outer for loop should control the row (0 through 7) and the inner for loop should control the column (0 through 7):
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
---|---|---|---|---|---|---|---|---|
0 | X | _ | X | _ | X | _ | X | _ |
1 | _ | X | _ | X | _ | X | _ | X |
2 | X | _ | X | _ | X | _ | X | _ |
3 | _ | X | _ | X | _ | X | _ | X |
4 | X | _ | X | _ | X | _ | X | _ |
5 | _ | X | _ | X | _ | X | _ | X |
6 | X | _ | X | _ | X | _ | X | _ |
7 | _ | X | _ | X | _ | X | _ | X |
No Comments