For a positive integer $n$, let $I_n=\int_{-\pi}^{\pi} \left(\frac{\pi}{2}-|x|\right)\cos nx\ dx$.

Find $I_1+I_2+I_3+I_4$.

[i]1992 University of Fukui entrance exam/Medicine[/i]
To solve the integral \( I_n = \int_{-\pi}^{\pi} \left(\frac{\pi}{2} - |x|\right) \cos(nx) \, dx \), we will use the properties of even and odd functions and the Fourier series.

1. **Break the integral into two parts:**
   \[
   I_n = \int_{-\pi}^{\pi} \left(\frac{\pi}{2} - |x|\right) \cos(nx) \, dx
   \]
   Since \(\frac{\pi}{2} - |x|\) is an even function and \(\cos(nx)\) is also an even function, their product is even. Therefore, we can simplify the integral by considering only the interval from \(0\) to \(\pi\) and doubling the result:
   \[
   I_n = 2 \int_{0}^{\pi} \left(\frac{\pi}{2} - x\right) \cos(nx) \, dx
   \]

2. **Split the integral:**
   \[
   I_n = 2 \left( \int_{0}^{\pi} \frac{\pi}{2} \cos(nx) \, dx - \int_{0}^{\pi} x \cos(nx) \, dx \right)
   \]

3. **Evaluate the first integral:**
   \[
   \int_{0}^{\pi} \frac{\pi}{2} \cos(nx) \, dx = \frac{\pi}{2} \int_{0}^{\pi} \cos(nx) \, dx
   \]
   The integral of \(\cos(nx)\) over \([0, \pi]\) is:
   \[
   \int_{0}^{\pi} \cos(nx) \, dx = \left[ \frac{\sin(nx)}{n} \right]_{0}^{\pi} = \frac{\sin(n\pi) - \sin(0)}{n} = 0
   \]
   Therefore,
   \[
   \int_{0}^{\pi} \frac{\pi}{2} \cos(nx) \, dx = \frac{\pi}{2} \cdot 0 = 0
   \]

4. **Evaluate the second integral using integration by parts:**
   Let \( u = x \) and \( dv = \cos(nx) \, dx \). Then \( du = dx \) and \( v = \frac{\sin(nx)}{n} \).
   \[
   \int_{0}^{\pi} x \cos(nx) \, dx = \left. x \frac{\sin(nx)}{n} \right|_{0}^{\pi} - \int_{0}^{\pi} \frac{\sin(nx)}{n} \, dx
   \]
   Evaluating the boundary term:
   \[
   \left. x \frac{\sin(nx)}{n} \right|_{0}^{\pi} = \frac{\pi \sin(n\pi)}{n} - \frac{0 \cdot \sin(0)}{n} = 0
   \]
   The remaining integral is:
   \[
   \int_{0}^{\pi} \frac{\sin(nx)}{n} \, dx = \frac{1}{n} \int_{0}^{\pi} \sin(nx) \, dx = \frac{1}{n} \left[ -\frac{\cos(nx)}{n} \right]_{0}^{\pi} = \frac{1}{n^2} \left( -\cos(n\pi) + \cos(0) \right)
   \]
   Since \(\cos(n\pi) = (-1)^n\) and \(\cos(0) = 1\):
   \[
   \int_{0}^{\pi} \frac{\sin(nx)}{n} \, dx = \frac{1}{n^2} \left( -(-1)^n + 1 \right) = \frac{1}{n^2} (1 - (-1)^n)
   \]
   Therefore,
   \[
   \int_{0}^{\pi} x \cos(nx) \, dx = -\frac{1}{n^2} (1 - (-1)^n)
   \]

5. **Combine the results:**
   \[
   I_n = 2 \left( 0 - \left( -\frac{1}{n^2} (1 - (-1)^n) \right) \right) = \frac{2}{n^2} (1 - (-1)^n)
   \]

6. **Sum \(I_1 + I_2 + I_3 + I_4\):**
   \[
   I_1 = \frac{2}{1^2} (1 - (-1)^1) = \frac{2}{1} (1 + 1) = 4
   \]
   \[
   I_2 = \frac{2}{2^2} (1 - (-1)^2) = \frac{2}{4} (1 - 1) = 0
   \]
   \[
   I_3 = \frac{2}{3^2} (1 - (-1)^3) = \frac{2}{9} (1 + 1) = \frac{4}{9}
   \]
   \[
   I_4 = \frac{2}{4^2} (1 - (-1)^4) = \frac{2}{16} (1 - 1) = 0
   \]
   Therefore,
   \[
   I_1 + I_2 + I_3 + I_4 = 4 + 0 + \frac{4}{9} + 0 = 4 + \frac{4}{9} = \frac{36}{9} + \frac{4}{9} = \frac{40}{9}
   \]

The final answer is \(\boxed{\frac{40}{9}}\).