Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add a merge array from 2 others arrays and print it

 
Victor Varela
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, Please I need your help.
I am asking for advice and help on:
(I already try many times but always one of the arrays became empty)

How to add a merge array from 2 others arrays and print it.
This is the code I have written:

 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor, welcome to the Ranch! We don't have too many rules here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/57515-how-add-merge-array-2-others-arrays.html
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to provide your merge method and explain what you have tried to do in it, before one could help you.

By the way, in the code that you have posted, method void display() is static, hence the calls arr.display(); and arr1.display(); are no different. In other words, they are going to perform exactly the same task regardless of which reference you are using to call it. This is why it is always recommended to call static methods using the class name (OrdArray.display();), which avoids confusion.

Please note that this method is printing only one of the two arrays (which may be what you want, but I'm not sure).
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Varela wrote:How to add a merge array from 2 others arrays and print it.

That's two separate tasks, and you don't appear to have tried either.
Another little rule we ask is that you ShowSomeEffort (←click).

And before you write your merge() method (or get any suggestions), you also need to tell us what it's supposed to do. As far as I know, all you might need is for it add one array onto the end of the other.

As far as displaying is concerned, you might want to have a look at Arrays.toString() (in fact a look at the whole java.util.Arrays class might not be a bad idea, because it has several methods that you can probably use).

Winston
 
Victor Varela
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried the following merge method



I have tried the following from main



it is giving me the error
The method merge(int[], int[]) in the type OrdArray is not applicable for the arguments (OrdArray,
OrdArrayb)
I have no clue how to mend it

 
Victor Varela
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
besides... I already have spent 30 hours trying everything I found on internet and still not working.
and this is the result that the program should get
array 1 after sorting
13 33 77
===================================================
array 2 after sorting
32 47 69 89 99
===================================================
Merged Array is:
13 32 33 47 69 77 89 99
===================================================
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Varela wrote:it is giving me the error
The method merge(int[], int[]) in the type OrdArray is not applicable for the arguments (OrdArray,
OrdArrayb)

And that's because those arguments are NOT int[]s; they're OrdArrays.

Winston
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Varela wrote:besides... I already have spent 30 hours trying everything I found on internet and still not working.
and this is the result that the program should get
array 1 after sorting
13 33 77
===================================================
array 2 after sorting
32 47 69 89 99
===================================================
Merged Array is:
13 32 33 47 69 77 89 99
===================================================

Then you need to look at your merge() method again, because that is NOT what it will produce.

Winston
 
Victor Varela
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

when I used the following is working ok the merge and the call method, but I need to make it work with arr and arr1 arrays



the code above prints:
Merged Array is:
13 32 33 47 69 77 89 99
===================================================
so the merge method is working ok
for that code
BUT, IT IS NOT what i need... i have to use the arrays created by main with arr.insert
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Varela wrote:the code above prints:
Merged Array is:
13 32 33 47 69 77 89 99
===================================================
so the merge method is working ok

Then you must have changed it since you posted, because the code you showed will NOT produce the results above; it will produce a concatenation of the two arrays.

Winston

[Edit] I see now that if you then run insert() on all the elements in your merged array, it might work; but that's NOT what you've posted so far.
 
Victor Varela
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not changed anything
what I need to make work is creating a third array which will be the merge of two arrays

the two arrays I create in main doing the following coding which will insert and sort them:


Then I have to create the third array as result of merging the two arrays created in main
and that is where i am lost

when I hardcoded the main using:


shows me that the merge method is working ok
but i have to remove that hardcode and use the arrays created with the inserts

in all thread of communications I have not changed the methods, code, examples, requirements

recap
I have created two arrays; now i have to create a third array, which is the merge of the two created
and i do not getting results with what i have tried so far


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic