# Some Logical problem

• 03-01-2010, 08:10 AM
MuslimCoder
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.
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.
• 03-01-2010, 08:14 AM