6. Using $1,2, \cdots, n$ to form an $n$-digit number without repeating digits, where 2 cannot be adjacent to 1 or 3, a total of 2400 different $n$-digit numbers are obtained. Then $n=$ $\qquad$

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly.
6.7 .

Obviously, $n \geqslant 4$, otherwise 2 must be adjacent to 1 or 3.
When 2 is adjacent to 1, there are $2 \cdot(n-1)$! arrangements, and when 2 is adjacent to 3, there are also $2 \cdot(n-1)$! arrangements. When 2 is adjacent to both 1 and 3, there are $2 \cdot(n-2)$! arrangements. Therefore, the number of arrangements that meet the conditions is
$$
\begin{array}{l}
n!-2 \cdot(n-1)!-2 \cdot(n-1)!+2 \cdot(n-2)! \\
=(n-2)!(n-2)(n-3) \\
=2400<7!.
\end{array}
$$

Moreover, $(n-2)$! $<7$!.
Thus, $n-2<7$. Therefore, $4 \leqslant n<9$.
Substituting $n=4,5,6,7,8$ into (1) in sequence, only when $n=7$
$$
5!\times 5 \times 4=2400
$$

satisfies the condition, hence $n=7$.