We apply a finite-difference algorithm that combines the local one-dimensional approximation and the Crank-Nicolson algorithms to solve the three-dimensional nonlinear Schrödinger equation. This scheme is unconditionally stable and accurate to second order. Therefore it offers a simple and accurate means to study a two-dimensional Z scan for arbitrary beam shape and medium length. As an example, we analyze the characteristics of a Z scan by utilizing an elliptic Gaussian beam for a thick nonlinear medium. The effects of ellipticity and waist separation of the elliptic beam on the normalized transmittance of the closed-aperture and open-aperture Z scan are demonstrated.