Results 1 to 5 of 5
  1. #1
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Question 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. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And your problem is?

  3. #3
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    Its not working? it usually returns true regardless... I still cant find the bug.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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. #5
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    It works now, <smile> Thanks for the advise. I hope the bug does pop up again...

Similar Threads

  1. Replies: 1
    Last Post: 01-27-2010, 11:43 AM
  2. Logical Gates
    By lingz89 in forum New To Java
    Replies: 1
    Last Post: 08-17-2009, 02:11 AM
  3. Logical JDBC problem
    By nick2price in forum Advanced Java
    Replies: 3
    Last Post: 10-03-2008, 12:34 AM
  4. Listing Logical Drives
    By Juggler in forum New To Java
    Replies: 3
    Last Post: 08-10-2008, 08:08 AM

Posting Permissions

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