Iteration with 2D Array
Example of 2D array art
class CarLoop {
String [][] car;
public CarLoop() {
car = new String[][]{
{
" ",
" ______ ",
" /|_||_\\`.__ ",
"( _ _ _\\ ",
"=`-(_)--(_)-' ",
"==============================================================="
},
{
" ",
" _/\\______\\__ ",
" / -. -|- ,-.`-. ",
" `( o )----( o )-' ",
" `-' `-' ",
"==============================================================="
},
{
" _________________________ ",
" | | | | | | \\ ",
" |___|_____|_____|____|_|___\\ ",
" | | | \\ ",
" `--(o)(o)--------------(o)--' ",
"==============================================================="
},
{
" ",
" _____________ ",
" ||______][__ \\\\____ ",
" |o _ |- | _ o)",
" '---(_)-------(_) '",
"==============================================================="
},
};
}
public void printRace() {
System.out.println();
System.out.println("Car drivng down in Java Loop");
int carPlace = 4;
for (int i = carPlace; i >= 1; i--)
{
System.out.println(i + " cars left in the race");
for (int row = 0; row < carPlace; row++) {
for (int col = 0; col < car[row].length; col++) {
System.out.println(car[row][col] + " ");
}
}
carPlace -= 1;
}
}
public static void main(String[] args) {
new CarLoop().printRace();
}
}
CarLoop.main(null);
Hacks
Build you own Jupyter Notebook. Feel free to use any ASCII art of your choice, there are some much better ones here. My little guys were made up out of my head while looking at unicode characters.
- Print monkeys horizontally versus vertically.
- Build more or entire rhyme for the "Monkey Jumpers" countdown poem
- Add names or other properties to the monkeys
In you notebook, illustrate or answer some of these questions.
Is this program in more of an Imperative Programming Style or OOP style? Explain. Observe variable assignments.
-
Is each Monkey an object? Build an where the monkey is an object versus two-dimensional array. This would be leading into Unit 5 requirements.
-
Study loops and zero based counting Study two-dimensional (2D) array references Explain different way you can access a 2D array