1. Senior Member
Join Date
Jan 2009
Posts
119
Rep Power
0

## Some Logical problem

Hi,

I am writting a method that is suppose to get a vector of Coordinate objects Objects, afterwards its suppose to get the value the coordinates are pointing to on a two dimensional array and compare to see if they all have thesame value. if they are all thesame it returns true, else if anyone of them is different then it returns false.

Here is what I got to muster so far.
Java Code:
```//checks Move elements and the value in their coordinates, if the values are same it reutnr true
//else it returns false
public boolean areSame(Vector<Move> nbrs)
{
Move p1, p2; //pointer one and pointer two
int v1, v2; //value being pointed at
boolean b = true; // b starts with true because we need it for and operations which would determine

if(nbrs.size() >= getConnect()) // if the no. of elements is less than number to connect
{
for(int i = 0; i < nbrs.size() -1 ; ++i)
{

p1 = nbrs.get(i);       v1 = board[p1.getX()] [p1.getY()]; //get the Move and finds its value on the board
p2 = nbrs.get(i + 1);   v2 = board[p2.getX()] [p2.getY()]; // get the one next to it and find its value on the board

b = b && (v1 == v2); // compare the next two values , This would

}
return b;
}else
return false;//end of check length

}```
I was thinking of using comparing in twos, like we A B C D we compare A B and store boolean in b. compare B C, store in b by b = b && (B == C) so that it doesn't overwrite a false when we get one.

2. Senior Member
Join Date
Jun 2008
Posts
2,562
Rep Power
8

3. Senior Member
Join Date
Jan 2009
Posts
119
Rep Power
0
Its not working? it usually returns true regardless... I still cant find the bug.

4. Senior Member
Join Date
Jun 2008
Posts
2,562
Rep Power
8
Use a debugger and step through the code so that you can actually see what's happening, rather than guessing at it. As an alternative, put in a plethora of print statements to print out every possible value that play a role each step of the way to do the same.

5. Senior Member
Join Date
Jan 2009
Posts
119
Rep Power
0
It works now, <smile> Thanks for the advise. I hope the bug does pop up again...

#### Posting Permissions

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