/**
 * Demonstrates the use of initializer lists and for-each loops with two-dimensional
 * arrays.
 *
 * @author Drue Coles
 */
public class TableOfFruits {

    public static void main(String[] args) {
 
        // Create a table of fruits and print them.
        String[][] fruits = {
            {"apple", "banana", "cherry", "date"},
            {"fig", "guava", "mango", "kumquat"},
            {"jackfruit", "papaya", "quince", "yuzu"}
        };
        printArray(fruits);
        
        // Format strings in the array so that columns in the output are right-justified. 
        for (String[] row : fruits) {
            for (int j = 0; j < row.length; j++) {
                row[j] = String.format("%9s", row[j]);
            }
        }
        printArray(fruits);
    }

    /**
     * Prints the contents of a two-dimensional array of strings.
     */
    private static void printArray(String[][] arr) {
        for (String[] row : arr) {
            for (String str : row) {
                System.out.print(str + " ");
            }
            System.out.println();
        }
        System.out.println();
    }
}