Nested Loops

This assignment is designed to give you additional practice with nested loops. Also, it is awesome.

The Infamous Letter Cube

import java.util.Scanner;

public class LetterCube
{
    public static void main( String[] args )
    {
        System.out.println("Welcome to the infamous Letter Cube!\n");
        LetterCube cube = new LetterCube();
        Scanner console = new Scanner( System.in );
        String side;
        
        do
        {
            System.out.print("Which side: ");
            side = console.next();
            if ( side.equals("front") )
                cube.showFront();
            else if ( side.equals("back") )
                cube.showBack();
            // etc
        } while ( ! side.equals("quit") );
    }

    private String[][][] cube;

    public LetterCube()
    {
        cube = new String[3][3][3];
        char c = 'A';

        for ( int L=0; L<3; L++ )
            for ( int R=0; R<3; R++ )
                for ( int C=0; C<3; C++ )
                    cube[L][R][C] = new String( "" + c++ );
                    //   ^  ^  ^
                    //   |  |  |
                    //   |  |  +-- column
                    //   |  +----- row
                    //   +-------- layer
    }

    public void showFront()
    {
        // layer fixed at 0, rows go forward, columns go forward
        for ( int r=0; r<3; r++ )
        {
            for ( int c=0; c<3; c++ )
            {
                System.out.print( cube[0][r][c] );
            }
            System.out.println();
        }
    }

    public void showBack()
    {
    }
}
Welcome to the infamous Letter Cube!

Which side: front

ABC
DEF
GHI

Which side: back

UTS
XWV
[ZY

Which side: left

SJA
VMD
YPG

Which side: right

CLU
FOX
IR[

Which side: top

STU
JKL
ABC

Which side: bottom

GHI
PQR
YZ[

Which side: quit