We know that

$\left| \cos x \right|=\cos x$in $\left[ 0,\pi /2 \right)$

$\left| \cos x \right|=-\cos x$in $\left[ \pi /2,3\pi /2 \right)$

$\left| \cos x \right|=\cos x$in $\left[ 3\pi /2,2\pi  \right]$

$y=\int _{0}^{\pi /2}\left| \cos x \right|dx+\int _{0}^{3\pi /2}\left| \cos x \right|dx+\int _{0}^{2\pi }\left| \cos x \right|dx$

$y=\int _{0}^{\pi /2}\cos xdx-\int _{\pi /2}^{3\pi /2}\cos xdx+\int _{3\pi /2}^{2\pi }\cos xdx$

$y=(\sin x)_{0}^{\pi /2}-\left( \sin x \right)_{\pi }^{3\pi /2}+\left( \sin x \right)_{3\pi /2}^{2\pi }$

$y=(1-0)-1-1+(0+1)=4$