2022-09-13 2D Arrays
Using 2d Arrays
class BirdsLoop {
String [][] birds;
public BirdsLoop(){
birds = new String[][]{
{
"/\\ /\\",
"((ovo))",
"():::()",
"VVV"
},
{
"/\\ /\\",
"((ovo))",
"():::()",
"VVV"
},
{
"/\\ /\\",
"((ovo))",
"():::()",
"VVV"
},
{
"/\\ /\\",
"((ovo))",
"():::()",
"VVV"
},
{
"/\\ /\\",
"((ovo))",
"():::()",
"VVV"
},
};
}
public void printPoem() {
System.out.println();
System.out.println("Birds Flying Poem in Java Loopy");
System.out.println("---------------------------------");
int birdsCount = birds.length;
for (int i = birdsCount; i >= 1; i--)
{
System.out.println(i + " birds flying in the house...");
int partCount = birds[0].length;
for (int row = 0; row < partCount; row++) {
for (int col = 0; col < birdsCount; col++) {
System.out.print(birds[col][row] + " ");
}
System.out.println();
}
System.out.println("One got caught and lost his head.");
birdsCount -= 1;
}
System.out.println("No more birds in the house");
System.out.println("------------------------------------");
System.out.println(" THE END ");
}
public static void main(String[] args) {
new BirdsLoop().printPoem();
}
}
BirdsLoop.main(null);