Skip to main content
added 3 characters in body
Source Link
Alnitak
  • 441
  • 2
  • 7

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, and I would actually call that variable sum (renaming your sum to target) since it's not really a "count" at all, e.g:

private boolean rowCheck(){
    int target = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int sum = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            sum += board[i][j];
        }
        if (sum != target) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sumtarget into a class member, calculated in the constructor.

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, and I would actually call that variable sum (renaming your sum to target) since it's not really a "count" at all, e.g:

private boolean rowCheck(){
    int target = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int sum = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            sum += board[i][j];
        }
        if (sum != target) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sum into a class member, calculated in the constructor.

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, and I would actually call that variable sum (renaming your sum to target) since it's not really a "count" at all, e.g:

private boolean rowCheck(){
    int target = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int sum = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            sum += board[i][j];
        }
        if (sum != target) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move target into a class member, calculated in the constructor.

added 120 characters in body
Source Link
Alnitak
  • 441
  • 2
  • 7

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, and I would actually call that variable sum (renaming your sum to target) since it's not really a "count" at all, e.g:

private boolean rowCheck(){
    int sumtarget = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int countsum = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            countsum += board[i][j];
        }
        if (countsum != sumtarget) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sum into a class member, calculated in the constructor.

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, e.g:

private boolean rowCheck(){
    int sum = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int count = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            count += board[i][j];
        }
        if (count != sum) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sum into a class member, calculated in the constructor.

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, and I would actually call that variable sum (renaming your sum to target) since it's not really a "count" at all, e.g:

private boolean rowCheck(){
    int target = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int sum = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            sum += board[i][j];
        }
        if (sum != target) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sum into a class member, calculated in the constructor.

added 58 characters in body
Source Link
Alnitak
  • 441
  • 2
  • 7

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, e.g:

private boolean rowCheck(){
    int sum = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int count = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            count += board[i][j];
        }
        if (count != sum) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sum into a class member, calculated in the constructor.

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, e.g:

private boolean rowCheck(){
    int sum = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int count = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            count += board[i][j];
        }
        if (count != sum) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards.

I would probably also move sum into a class member, calculated in the constructor.

Your setting of count = 0 should be immediately before the appropriate for loop, not after it, e.g:

private boolean rowCheck(){
    int sum = size * (size + 1) / 2;
    for (int i = 0; i <size; i++) {
        int count = 0;        // declaration moved, too
        for (int j = 0; j < size ; j++) {
            count += board[i][j];
        }
        if (count != sum) return false;
    }
    return true;
}

The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).

I would probably also move sum into a class member, calculated in the constructor.

Source Link
Alnitak
  • 441
  • 2
  • 7
Loading