hi all

i am a student 6 weeks into learning java.

i have been attempting to create a simple Mastermind game using java, non object oriented version. However, I have been stuck at the part where the program counts the "number of pegs that are of the correct color but placed at the wrong position". It either overlaps with the "number of pegs of the right color at the correct position" or it under-counts.

The following is the segment of my code:

Code:
	public static int incorrectPosition(int row) {
		int incorrectCount = 0;

		/*
		 * board[row][col] 
		 * Loop for each column in the current row. 
		 * Loop for
		 * each value in the code. Check if column matches value but not in the
		 * same position.
		 */

		for (int col = 0; col < SIZE; col++) {
			for (int index = 0; index < SIZE; index++) {
				if ((!board[row][col].equalsIgnoreCase(secretCode[col]))
						&& board[row][col].equalsIgnoreCase(secretCode[index])) {
					if ((col != 3)
							&& (!board[row][index]
									.equalsIgnoreCase(secretCode[index]))) {
						if ((!board[row][col + 1]
								.equalsIgnoreCase(secretCode[index]))) {
							incorrectCount++;
						}
					} else if (col == 3
							&& (!board[row][index]
									.equalsIgnoreCase(secretCode[index]))) {
						if (!(board[row][0].equalsIgnoreCase(secretCode[index])
								|| board[row][1]
										.equalsIgnoreCase(secretCode[index]) || board[row][2]
								.equalsIgnoreCase(secretCode[index]))) {
							incorrectCount++;
						}

					}

				}
			}
		}

		return incorrectCount;

	}

Would appreciate if someone could advice me with regards to this problem.
Thank you!