Iteration Rhyme Example
This code shows a rhyme with deer and tigers
Here, I am using an example of deer getting hunted by tigers using iteration. Unlike the example from Mr. M I changed the for loops so the deer would print horizontally instead of vertically making it more compact.
import java.util.*;
public class DeerTiger {
String[][] deers = {
{
"( ) ",
" `--(_ _)--' ",
" Y-Y ",
" /@@ \\ ",
" / \\ ",
" `--'. \\ , ",
" | `.__________/) ",
" ",
" "
},
{
"\\|/ \\|/ ",
" \\ / ",
" \\_/ ___ ___ ",
" o o-' ''' ' ",
" O -. |\\ ",
" | |'''| | ",
" || | | ",
" || || ",
" \" \" "
},
{
" { } ",
" {^^, ",
" ( `-; ",
" _ `;;~~ ",
" /(______); ",
" ( ( ",
" |:------( ) ",
" _// \\\\ ",
"/ / vv "
},
{
" ()",
" )) ((",
" // \\\\",
" | \\\\____// |",
"\\~/ ~ ~\\/~~/",
" (| _/o ~~",
" / / ,|",
" (~~~)__.-\\ |",
" ``~~ | |",
" | | |"
}
};
String[] tiger = {
" __,,,,_",
" _ __..-;''`--/'/ /.',-`-.",
" /'`\\ \\ | \\ | \\| // // / -.,/_,'-,",
" /<7' ; \\ \\ | ; ||/ /| | \\/ |`-/,/-.,_,/')",
" / _.-, `,-\\,__| _-| / \\ \\/|_/ | '-/.;.\\'",
" `-` f/ ; / __/ \\__ `/ |__/ |",
" `-' | -| =|\\_ \\ |-' |",
" __/ /_..-' ` ),' //",
" fL ((__.-'((___..-'' \\__.'"
};
public void printRhyme () {
for (int count = 4; count >= 1; count--) {
System.out.println("Here comes " + count + " deer\n");
for (int i = 0; i<deers[0].length; i++) {
for (int j = 0; j<count; j++) {
System.out.print(deers[j][i] + " ");
}
System.out.println();
}
System.out.println("Then the tiger arrives");
for (int i = 0; i<tiger.length; i++) {
System.out.println(tiger[i]);
}
System.out.println();
System.out.println("Now there are " + (count-1) + " deer\n");
}
}
}
DeerTiger myRhyme = new DeerTiger();
myRhyme.printRhyme();