This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question about Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about Arrays" Watch "Question about Arrays" New topic

Question about Arrays

Kevin Behr

Joined: Jun 29, 2006
Posts: 23
Hello, I have two arrays: useCode[] and board[][].

Each array contains four colors (for the 2D array (board), each row contains four colors).

What I am looking to do is to compare the two arrays. I am looking to increment the integer variable 'none' for every color that exists in
board[][], but does not exist in useCode[].

Does anyone have any suggestions how I might accomplish this? So far, this is what I have:

I count how many times each color appears. But, since there are a total of six colors, and each array can only has four colors, I need a way to compare the two arrays...

I hope that makes sense, thanks for any help!
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I am looking to increment the integer variable 'none' for every color that exists in board[][], but does not exist in useCode[].

When you say "for every color that exists in board[][]" do you mean exists in any of the rows in board? Or a specific row?

I need a way to compare the two arrays

Can you elaborate on what you mean by "compare the two arrays". Since one is a two dimensional array, and the other is not, you can't directly compare the arrays. So they can never be "equal".

Are you trying to determine if a row array from the board 2D Array matches the useCode array in that they both have the same colors? And if so, do the four colors in each array need to be in the same order? Or just that each array contains the same colors? And then do you need to do that for each row?

I think it would be helpful to post more details about the problem. Perhaps post the full problem statement and directions. I think it will be easier then to point you in the right direction.

Also, just so we can guide you correctly... this sounds like it might be an assignment from a programming class. If so, do the directions explicitly state you must use arrays to solve the problem? Have you learned about other data collections yet?
Have you checked out Aspose?
subject: Question about Arrays
It's not a secret anymore!