Iteration is useful, as it allows us to go through a list of items very quickly. We can easily store a list of things in an array and then call each of the elements with a simple line of code rather than having to write the entire thing again. All in all, Iteration just makes life a lot easier.

The Solar System

Here we are going to be demonstrating how 2D Array's and iteration work by taking a trip through the Solar System!

public class SolarSystem{
    String [][] solarsystem;

    public SolarSystem(){
        solarsystem = new String[][]{
            {
                "         ,MMM8&&&.         ",
                "    _...MMMMM88&&&&..._    ",
                " .::'''MMMMM88&&&&&&'''::. ",
                "::     MMMMM88&&&&&&     ::",
                "'::....MMMMM88&&&&&&....::'",
                "   `''''MMMMM88&&&&''''`   ",
                "          'MMM8&&&'        "
            },
            {
                "        _____          ",
                "    ,-:` \\;',`'-,     ",
                "  .'-;_,;  ':-;_,'.    ",
                " /;   '/    ,  _`.-\\  ",
                "| '`. (`     /` ` \\`| ",
                "|:.  `\\`-.   \\_   / |",
                "|     (   `,  .`\\ ;'| ",
                " \\     | .'     `-'/  ",
                "  `.   ;/        .'    ",
                "    `'-._____.         "
            },
            {
                "                     .::.",
                "                  .:'  .:",
                "        ,MMM8&&&.:'   .:'",
                "       MMMMM88&&&&  .:'  ",
                "      MMMMM88&&&&&&:'    ",
                "      MMMMM88&&&&&&      ",
                "    .:MMMMM88&&&&&&      ",
                "  .:'  MMMMM88&&&&       ",
                ".:'   .:'MMM8&&&'        ",
                ":'  .:'                  ",
                "'::'                     "
            },
            {
                "          _.._   ",
                "        .' .-'`  ",
                "       /  /      ",
                "       |  |      ",
                "       \\  '.___.;",
                "        '._  _.' ",
                "           ``    "
            }
        };
    }

    public void print(){
        System.out.println(" ");
        System.out.println("The Solar System");
        
        int solarSystemCount = solarsystem.length;
        for (int i = solarSystemCount; i > 0; i--){
            System.out.println(i + " Planets left to go..");

            for (int col = 0; col < solarsystem[0].length; col++){
                for (int row = 0; row < i; row++){
                    System.out.print(solarsystem[row][col] + "\t");
                }
                
                System.out.println();
            }
            System.out.println("The Sun ate a planet whole");
            System.out.println("We say RUN RUN RUN FROM THE SUN");
            System.out.println("\n--------------------------------------\n");
            solarSystemCount -= 1;  
        }

        System.out.println("No more planets in space :( \n");
        System.out.println("--------------------------------------");
        System.out.println("             THE END              ");
     
    }
    public static void main(String[] args){
        new SolarSystem().print();
    }
}

SolarSystem.main(null);
 
The Solar System
4 Planets left to go..
         ,MMM8&&&.         	        _____          	                     .::.	          _.._   	
    _...MMMMM88&&&&..._    	    ,-:` \;',`'-,     	                  .:'  .:	        .' .-'`  	
 .::'''MMMMM88&&&&&&'''::. 	  .'-;_,;  ':-;_,'.    	        ,MMM8&&&.:'   .:'	       /  /      	
::     MMMMM88&&&&&&     ::	 /;   '/    ,  _`.-\  	       MMMMM88&&&&  .:'  	       |  |      	
'::....MMMMM88&&&&&&....::'	| '`. (`     /` ` \`| 	      MMMMM88&&&&&&:'    	       \  '.___.;	
   `''''MMMMM88&&&&''''`   	|:.  `\`-.   \_   / |	      MMMMM88&&&&&&      	        '._  _.' 	
          'MMM8&&&'        	|     (   `,  .`\ ;'| 	    .:MMMMM88&&&&&&      	           ``    	
The Sun ate a planet whole
We say RUN RUN RUN FROM THE SUN

--------------------------------------

3 Planets left to go..
         ,MMM8&&&.         	        _____          	                     .::.	
    _...MMMMM88&&&&..._    	    ,-:` \;',`'-,     	                  .:'  .:	
 .::'''MMMMM88&&&&&&'''::. 	  .'-;_,;  ':-;_,'.    	        ,MMM8&&&.:'   .:'	
::     MMMMM88&&&&&&     ::	 /;   '/    ,  _`.-\  	       MMMMM88&&&&  .:'  	
'::....MMMMM88&&&&&&....::'	| '`. (`     /` ` \`| 	      MMMMM88&&&&&&:'    	
   `''''MMMMM88&&&&''''`   	|:.  `\`-.   \_   / |	      MMMMM88&&&&&&      	
          'MMM8&&&'        	|     (   `,  .`\ ;'| 	    .:MMMMM88&&&&&&      	
The Sun ate a planet whole
We say RUN RUN RUN FROM THE SUN

--------------------------------------

2 Planets left to go..
         ,MMM8&&&.         	        _____          	
    _...MMMMM88&&&&..._    	    ,-:` \;',`'-,     	
 .::'''MMMMM88&&&&&&'''::. 	  .'-;_,;  ':-;_,'.    	
::     MMMMM88&&&&&&     ::	 /;   '/    ,  _`.-\  	
'::....MMMMM88&&&&&&....::'	| '`. (`     /` ` \`| 	
   `''''MMMMM88&&&&''''`   	|:.  `\`-.   \_   / |	
          'MMM8&&&'        	|     (   `,  .`\ ;'| 	
The Sun ate a planet whole
We say RUN RUN RUN FROM THE SUN

--------------------------------------

1 Planets left to go..
         ,MMM8&&&.         	
    _...MMMMM88&&&&..._    	
 .::'''MMMMM88&&&&&&'''::. 	
::     MMMMM88&&&&&&     ::	
'::....MMMMM88&&&&&&....::'	
   `''''MMMMM88&&&&''''`   	
          'MMM8&&&'        	
The Sun ate a planet whole
We say RUN RUN RUN FROM THE SUN

--------------------------------------

No more planets in space :( 

--------------------------------------
             THE END