Again i need some advice please

Sorry to bother you that much.

I have a project that contain an array of people(each index contain name,salary and id number).

i need to make a matrix that each name will be in a new row.

so i did count how many different names i have(this is what will be my matrix size).

but i am not sure how to continue ,any ideas?

example:"console" -this is my array:{

1 james bond 1000

2 tami 400

3 james bond 500

4 tami 1

5 james bond 1} first-id,second-name,third-salary.{5 indexes}

i need to make matrix (for this example will be): { james bond james bond james bond

tami tami}

hope that you understood if not nvm but thanks for any help

Re: Again i need some advice please

Is that a 2 dim String array? Can you post code that shows how it is defined? It needs "s and , to show what the elements in the array are.

Quote:

i need to make matrix

That looks like a one dim array? Is that correct?

Is the content of the one dim array copied from the first column of the 2 dim array?

Re: Again i need some advice please

Quote:

Originally Posted by

**Norm**
Is that a 2 dim String array? Can you post code that shows how it is defined? It needs "s and , to show what the elements in the array are.

That looks like a one dim array? Is that correct?

Is the content of the one dim array copied from the first column of the 2 dim array?

You know what lets say i have an array of strings{"james","john","james","john","james"}

I need to initialize a matrix that each row contain a different name.

--- Update ---

The output will be a matric look like that: john john john

james james

--- Update ---

3 times james***

2 times john.

Each in sep row .

Re: Again i need some advice please

What have you tried?

The code would have some loops and do compares on what it sees in the one dim array.

When the contents of the one dim array changes, the code would go to the next row in the 2 dim array that is being filled.

Re: Again i need some advice please

Code :

int arr[]=new int[]{1,1,1,2,2};
int row=2; //two different number=two rows
int[][]matrix=new int[row][];
for (int i=0;i<matrix.length;i++){
for(int j=0;j<matrix[i].length;j++){
}
}

I stuck on how do i apply this via matrix to get in one row (3 times '1'): 1 1 1

and second row(different number '2') : 2 2

Re: Again i need some advice please

Is the contents of the one dim array sorted? That will make it much easier.

Stop writing code until you can explain what the the code must do.

Can you explain in English the steps the code must do to scan a one dim array and find all the elements in it that should go on a row of the two dim array?

Also it needs to determine how many rows are needed.

Re: Again i need some advice please

yes it is sorted.

i need to make a matrix from this array -each row different number and the times the number occuered

1.i need to check how many numbers are different to determine how many rows i need(i check and i need 2 rows)

2.and here is where i am stuck , i need to make a matrix from that(i hope you understand).

here is what i'v tried so far but the program fail:

Code :

int arr[]=new int[]{1,1,1,2,2};
int row=2;
int[][]matrix=new int[row][];
for (int i=0;i<row;i++){
for(int j=0;j<arr.length;j++){
if(arr[i]!=arr[i+1]){
matrix[i][j]=arr[i];
}
}
}

Re: Again i need some advice please

Quote:

i need to make a matrix from that

What does "make" mean?

At least two parts to that:

define the size of each row

copy the values from the one dim array to a row in the two dim array

What does the code need to do to determine the size of a row in the two dim array?

When it gets the size, then it can define the size of the row.

The posted code has the number of rows hard coded, vs doing a scan to compute the number of rows needed. That's ok for testing, but will need to be changed later to do a scan to count the number of rows needed.

Re: Again i need some advice please

yes for array of example like i show{1 1 1 2 2}

to matrix like that: 1 1 1

2 2

i count the number of different number=2.that's the row number.

but how can i continue from their?can you show me the right way?or direct me.

i am completely lost here

Re: Again i need some advice please

Now you need to scan the one dim array and find the number of like numbers that will go on each row so the code can define the array with the correct size.

With {1 1 1 2 2} the first row would have 3 and the second row 2. Use a loop to scan the array to count the like numbers.