/*
 * @author BKChepkwony
 * Created on 24 Aug 2011
 */
package com.jjpeople.arrays;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

/**
 * Class demonstrating usage of arrays
 *
* @author BKChepkwony
 * Created on 24 Aug 2011
 */
/**
 * @author BKChepkwony
 * Created on 24 Aug 2011
 */
public class ArrayExample {

    // Getting logger used for logging statements.
    public Logger logger =
        Logger.getLogger( ArrayExample.class );

    private static final String END_OF_LINE_CHARACTER =
        System.getProperty( "line.separator" );

    private static final String SECTION_SEPERATOR =
        "=========================================" +
            "=======================================";


    /**
     * Prints a line with the correct end of line character
     *
     * @example The example the message came from
     * @param message The message to print
     *
     */
    private void print( String example, String message ) {

        print( example + " : " + message );
    }


    /**
     * Prints a line with the correct end of line character
     *
     * @param message The message to print
     */
    private void print( String message ) {

        System.out.println( message + END_OF_LINE_CHARACTER );
    }


       /**
     * Demonstrates initializing and populating a multi-dimensional array
     * in one statement
     */
    private void personalDetails() {

        logger.debug( "personalDetails()" );

        String[][][] personArray =
            {
              { "John",  " Muray", "1-10-1982" },
              { "Peter",  " Kamau", "2-5-1987" },
              { "Mary",  " Wambui", "8-5-1988" },
              { "Bethu",  " Kips", "8-8-1987" },
              { "Cetera",  " Omosh", "2-5-1987" }

            };
             String  message = "Names:" +
              personArray[0][0] [0]+personArray[0][1] [0]  +"DOB: "  +personArray[0][1] [1];
              print( "personalDetails()", message );
              message = "Names:" +
              personArray[1][0] [0] + personArray[1][1] [0]  +"DOB: " + personArray[1][1] [1];
                print( "printPersonalD()", message );
                message = "Names:" +
              personArray[2][0] [0] + personArray[2][1] [0]  +"DOB: "  +personArray[2][1] [1];
                print( "printPersonalD()", message );
                message = "Names:" +
              personArray[3][0] [0] + personArray[3][1] [0]  +"DOB: "  +personArray[3][1] [1];
                print( "printPersonalD()", message );
               message = "Names:" +
              personArray[4][0] [0] + personArray[4][1] [0] +"DOB: " +personArray[4][1] [1];
                print( "printPersonalD()", message );


       
    }


    /**
     * shows the contents of the multi dimensional array.
     * Use the printPersonalD()
     */
    private void printPersonalD() {

     logger.debug( "printPersonalD()" );
     print( SECTION_SEPERATOR );
     personalDetails();
     print( SECTION_SEPERATOR );

       
       
    }


    /**
     * Constructor
     */
    public ArrayExample() {
        super();
    }


   

    /**
     * This is the starting execution point of the program.
     *
     * @param args the args are parameters passed into this java program from
     * the command line. In this example no parameters are being passed into
     * this programme.
     */
    public static void main( String[] args ) {

        // Configure the logger to print to the screen
        BasicConfigurator.configure();

        ArrayExample myArrayExample = new ArrayExample();
        myArrayExample.printPersonalD();
    }
}
/*
 * @author BKChepkwony
 * Created on 24 Aug 2011
 */
package com.jjpeople.arrays;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

/**
 * Class demonstrating usage of arrays
 *
* @author BKChepkwony
 * Created on 24 Aug 2011
 */
/**
 * @author BKChepkwony
 * Created on 24 Aug 2011
 */
public class ArrayExample {

    // Getting logger used for logging statements.
    public Logger logger =
        Logger.getLogger( ArrayExample.class );

    private static final String END_OF_LINE_CHARACTER =
        System.getProperty( "line.separator" );

    private static final String SECTION_SEPERATOR =
        "=========================================" +
            "=======================================";


    /**
     * Prints a line with the correct end of line character
     *
     * @example The example the message came from
     * @param message The message to print
     *
     */
    private void print( String example, String message ) {

        print( example + " : " + message );
    }


    /**
     * Prints a line with the correct end of line character
     *
     * @param message The message to print
     */
    private void print( String message ) {

        System.out.println( message + END_OF_LINE_CHARACTER );
    }


       /**
     * Demonstrates initializing and populating a multi-dimensional array
     * in one statement
     */
    private void personalDetails() {

        logger.debug( "personalDetails()" );

        String[][][] personArray =
            {
              { "John",  " Muray", "1-10-1982" },
              { "Peter",  " Kamau", "2-5-1987" },
              { "Mary",  " Wambui", "8-5-1988" },
              { "Bethu",  " Kips", "8-8-1987" },
              { "Cetera",  " Omosh", "2-5-1987" }

            };
             String  message = "Names:" +
              personArray[0][0] [0]+personArray[0][1] [0]  +"DOB: "  +personArray[0][1] [1];
              print( "personalDetails()", message );
              message = "Names:" +
              personArray[1][0] [0] + personArray[1][1] [0]  +"DOB: " + personArray[1][1] [1];
                print( "printPersonalD()", message );
                message = "Names:" +
              personArray[2][0] [0] + personArray[2][1] [0]  +"DOB: "  +personArray[2][1] [1];
                print( "printPersonalD()", message );
                message = "Names:" +
              personArray[3][0] [0] + personArray[3][1] [0]  +"DOB: "  +personArray[3][1] [1];
                print( "printPersonalD()", message );
               message = "Names:" +
              personArray[4][0] [0] + personArray[4][1] [0] +"DOB: " +personArray[4][1] [1];
                print( "printPersonalD()", message );


       
    }


    /**
     * shows the contents of the multi dimensional array.
     * Use the printPersonalD()
     */
    private void printPersonalD() {

     logger.debug( "printPersonalD()" );
     print( SECTION_SEPERATOR );
     personalDetails();
     print( SECTION_SEPERATOR );

       
       
    }


    /**
     * Constructor
     */
    public ArrayExample() {
        super();
    }


   

    /**
     * This is the starting execution point of the program.
     *
     * @param args the args are parameters passed into this java program from
     * the command line. In this example no parameters are being passed into
     * this programme.
     */
    public static void main( String[] args ) {

        // Configure the logger to print to the screen
        BasicConfigurator.configure();

        ArrayExample myArrayExample = new ArrayExample();
        myArrayExample.printPersonalD();
    }
}

Edited 5 Years Ago by peter_budo: Do not use code snippets for posting questions

I find this error:
Incompatible types
<"Cetera","Omosh","2-5-1987">
required:String []
Found: String.
Somebody shade some light please.
Best Regards,
Betny.

Assuming this error is around line 88 (and next time please post the line number with the error messages!) you define a 3-dimensional array,, but try to initialise it with data in the form of a 2-dimensional array. So when it looks inside the 2d array it expects to find one more level of array, but all it finds is a String.

Hallo, It does not show the line number where the error is located, Please still having difficulties, how am i supposed to initialize the data in 3-dimensional.
Best regards,
Betny.

Look again, compiler and runtime messages do show the line number.

Without a proper statement of what this code is supposed to do I can't comment on how to reconcile your 2d data with your 3d array. But all the following statements seem to have the third index as [0] all the time, so maybe the third dimension is not needed???

Thanx alot, yap the third index is not needed. I tried it and it worked, how am I supposed to populates the multi-dimensional array with data and another method that shows the contents of the multi dimensional array.
For example:

 private void personalDetails() {

        logger.debug( "personalDetails()" );

        String personArray [][] =
            {
              { "John",  " Muray", "1-10-1982" },
              { "Peter",  " Kamau", "2-5-1987" },
              { "Mary",  " Wambui", "8-5-1988" },
              { "Bethu",  " Kips", "8-8-1987" },
              { "Cetera",  " Omosh", "2-5-1987" }

            };   
 //Am i supposed to call the second method from here.
             personalDetailsContent(  personArray [][] );



    }

       /**
     * Demonstrates initializing and populating a multi-dimensional array
     * in one statement
     */
    private void personalDetailsContent() {

        logger.debug( "personalDetailsContent()" );




             String   message = "Names:" +
              personArray[0][0]  + personArray[0][1]  +   "\tDOB: "  +personArray[0] [2];
              print( "personalDetails()", message );
              message = "Names:" +
              personArray[1][0]  + personArray[1][1]  + "\tDOB: " + personArray[1][2] ;
                print( "personalDetails()", message );
                message = "Names:" +
              personArray[2][0]  + personArray[2][1]  +"\tDOB: "  +personArray[2][2] ;
                print( "personalDetails()", message );
                message = "Names:" +
              personArray[3][0]  + personArray[3][1]   +"\tDOB: "  +personArray[3][2] ;
                print( "personalDetails()", message );
               message = "Names:" +
              personArray[4][0] + personArray[4][1]  +"\tDOB: " +personArray[4][2] ;
                print( "personalDetails()", message );



    } 

Please someone help me how to do it.

Edited 3 Years Ago by pyTony: fixed formatting

This question has already been answered. Start a new discussion instead.