wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Comparing chars in array, by columns? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing chars in array, by columns?" Watch "Comparing chars in array, by columns?" New topic
Author

Comparing chars in array, by columns?

Lucas McLevinsky
Greenhorn

Joined: Jan 17, 2013
Posts: 1
Hello! My first topic here, haha. I have a question about comparing char values in an array with another array, however a bit differently:

Let's say I have a first array like this
0 0 1 0 1 0 1 0 1 0 1
0 0 1 1 1 1 0 0 1 0 1
0 0 0 1 0 1 0 1 0 1 0
And the second
0 1 1 1 0 0 0 1 0 1 0

Now I want to compare the value of the first index from the second array with the ENTIRE column of the first array - in other words I want to compare
[0] 0 1 0 1 0 1 0 1 0 1
[0] 0 1 1 1 1 0 0 1 0 1
[0] 0 0 1 0 1 0 1 0 1 0 - all three of those
with
[0] 1 1 1 0 0 0 1 0 1 0

And return 1 if they are all the same, 0 if they are different values, and 2 if the values from the corresponding column from the first array are all inversed values from the second (i.e. comparing "1" from the second array to all "0"'s from the first). And do this as many times, as the number of characters in the second array (in this case - 11)

Any clue how to do this? I need it as a part of an important project for me and I'd appreciate any help!

Cheers,
Lucas.
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 72

Well, what have you tried?

Your first array looks like an array of arrays, and with that all you'd have to look at is the first value of each array and compare that to whatever value.


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
Welcome to the Ranch

Since you have an array of arrays, you can use each element of it as an array in its own right.
I think you need to turn your computer off, and write down on paper how you intend to compare those arrays.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

Lucas McLevinsky wrote:And return 1 if they are all the same, 0 if they are different values, and 2 if the values from the corresponding column from the first array are all inversed values from the second (i.e. comparing "1" from the second array to all "0"'s from the first). And do this as many times, as the number of characters in the second array (in this case - 11)

Well, other than the good advice you've already been given, I have a few further tips.

1. When you're working out what you want to do: start with a single column, and describe exactly what you want to happen in English (or your native language), NOT in code-speak. Once you have that, you should be able to simply wrap it in a "for each column" loop.

2. What you've shown us look like binary digits rather than characters, so make them booleans, even if it means converting them first. If they really are characters, and they can contain values other than '1' and '0', then you need to explain exactly what you mean by "inversed values".

3. In your example, all arrays are the same length; but what if they aren't? Make sure you have a 'Plan B' for when input is invalid, even if it's just to let the program fail.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing chars in array, by columns?