Results 1 to 5 of 5
Thread: Some Logical problem
- 03-01-2010, 07:10 AM #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.
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.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 }
- 03-01-2010, 07:14 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
And your problem is?
- 03-01-2010, 07:16 AM #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.
- 03-01-2010, 07:22 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- 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.
- 03-01-2010, 08:12 AM #5
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
Similar Threads
-
Lucene logical view of index and running time
By toeh101 in forum LuceneReplies: 1Last Post: 01-27-2010, 10:43 AM -
Logical Gates
By lingz89 in forum New To JavaReplies: 1Last Post: 08-17-2009, 01:11 AM -
Logical JDBC problem
By nick2price in forum Advanced JavaReplies: 3Last Post: 10-02-2008, 11:34 PM -
Listing Logical Drives
By Juggler in forum New To JavaReplies: 3Last Post: 08-10-2008, 07:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks