You are not updating flag
declared in your main
method. Change each of
checkForWinner(board);
to
flag = checkForWinner(board);
Without this flag
will never change and you will never leave your while (flag != true)
(which could be simplified to while(!flag)
) loop which means you will never execute displayWinner(player, flag)
method.