Results 1 to 4 of 4
  1. #1
    Omer1233 is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Creating matrix using a sorted array

    say I'm given a sorted array of strings : {Max,Max,Max,Omer,Omer} How can i make a matrix that contains in each row the same names:

    Max , Max , Max

    Omer , Omer

    its a matrix of employees, so ive tried the following:

    Java Code:
    public static Employee[][] initMat(Employee[] eps)
        {
            Employee[][] mat = new Employee[eps.length][eps.length];
            for(int i = 0;i < mat.length-1; i++)
            {
                for(int j=i;j<mat[i].length-1;j++)
                {
                    if(eps[i].getName().equals(eps[i+1].getName()))
                        {
                            mat[i][j] = eps[i];
                            mat[i][j+1] = eps[i+1];
                        }
                }
    
            }
            return mat;
    Ty!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,406
    Rep Power
    25

    Default Re: Creating matrix using a sorted array

    Can you post the desired output for the String array you posted?
    What is in the array if there are fewer matching names on a row?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Omer1233 is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Re: Creating matrix using a sorted array

    With this given array : {Max,Max,Max,Omer,Omer}

    We should get this matrix
    |Max , Max , Max|
    |Omer , Omer|

    Ty for the quick response!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,406
    Rep Power
    25

    Default Re: Creating matrix using a sorted array

    Ok, that looks like every row in the 2 dim array can be a different length. Is that correct?
    If all the names are the same, there would only be one row.

    Now work on the logic for scanning through the 1 dim array separating its contents into the rows for the two dim array.
    Work out the details of the logic before trying to write the code.
    You'll need to determine the number of rows and the length of each row.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. how to delete an element from a sorted array
    By gnawk in forum New To Java
    Replies: 2
    Last Post: 07-12-2012, 09:48 PM
  2. Keeping objects sorted in an array.
    By artur in forum New To Java
    Replies: 6
    Last Post: 02-28-2012, 12:46 AM
  3. Checking to see if Array is sorted
    By pytho in forum New To Java
    Replies: 5
    Last Post: 07-06-2011, 01:39 AM
  4. Creating a 3x3 matrix of imgs
    By Zarcorp in forum Java Applets
    Replies: 6
    Last Post: 11-25-2010, 01:23 AM
  5. Replies: 0
    Last Post: 04-14-2008, 08:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •