【Example 1】Given sticks of lengths $1, 2, \cdots, n$, one of each length, how many different triangles can be formed with them?
If we denote the lengths of the three sides of a triangle as $a, b, c$, without loss of generality, assume $a \leq b \leq c$. We can classify these triangles based on the length of $c$, resulting in different classes such as $c=4, c=5, \cdots, c=n$. We denote the sets of triangles in each class as $B_{4}, B_{5}, \cdots, B_{n}$, respectively. These sets form a partition of the set of all triangles, so we can use formula (1) to find $|B|$.

In $B_{k}$, the three sides of the triangle are $a, b, k$, so all these lattice points lie within the triangular region bounded by the lines $a=b, a+b=k$, and $b=k$. Therefore, when $k$ is even, we have
$$
\left|B_{k}\right|=1+3+\cdots+(k-3)=\frac{1}{4}(k-2)^{2}
$$

When $k$ is odd, we have
$$
\left|B_{k}\right|=2+4+\cdots+(k-3)=\frac{1}{4}(k-1)(k-3)
$$

Thus, by formula (1), when $n$ is even, we have
$$
\begin{aligned}
|B| & =\left|B_{4}\right|+\left|B_{5}\right|+\cdots+\left|B_{n}\right| \\
& =\frac{1}{24} n(n-2)(2 n-5)
\end{aligned}
$$

When $n$ is odd, we have
$$
\begin{aligned}
|B| & =\left|B_{4}\right|+\left|B_{5}\right|+\cdots+\left|B_{n}\right| \\
& =\frac{1}{24}(n-1)(n-3)(2 n-1)
\end{aligned}
$$