Q:

Prove that $\mathbb{Q}\!\smallsetminus\!\mathbb{Z}$ is dense in $\mathbb{R}$

Can someone just tell me if this is a correct way to prove it. 
let $(a,b)$ be a nonempty open interval in $\mathbb{R}$. Then by density of $\mathbb{Q}$ in $\mathbb{R}$ there exists $q\in \mathbb{Q}$ s.t.  $a<q<b$.
Case 1: $b-q<1$ then there is a rational $q_0$ s.t.  $q<q_0<b$ but since $b-q<1$, it can not be the case that $q_0\in \mathbb{Z}$
case 2: $b-q\ge1$ then there exists rational $q_0$ s.t.  $a<q<q_0<q+1\le b$. Again $q_0\notin \mathbb{Z}$  $ \ \ \ $ $_\square$
Does this work? 

A:

Let $x\in\mathbb R$.
Set
$$
q=\left\{
\begin{array}{ccc}
\dfrac{\lfloor nx\rfloor}{n} & \text{if} & \dfrac{\lfloor nx\rfloor}{n}\not\in\mathbb Z, \\
\dfrac{\lfloor nx\rfloor}{n}+\dfrac{1}{2n} & \text{if} & \dfrac{\lfloor nx\rfloor}{n} \in\mathbb Z.
\end{array}
\right. 
$$
Then $q\in\mathbb Q\!\smallsetminus\!\mathbb Z$ and $\lvert x-q_n\rvert<\dfrac{1}{n}$.
Note.  By $\lfloor x\rfloor$ we denote the integer part of $x$.

