What are the flaps on the exhaust of military airplanes for?
Those flaps on exhaust are for thrust vectoring. A simple definition would be:


  the ability of an aircraft [...] to manipulate the direction of the
  thrust [...] to control the attitude [...] of the vehicle


F-22 uses it like this:


  [Its] nozzle [...] is the first vectoring nozzle. That means
  the pilot can move, or vector, the nozzle up and down by 20 degrees.
  
  The gases coming out of the vector nozzle help push the airplane's
  nose up or down. This vectoring increases the roll rate of the plane
  by 50 percent, making it much more maneuverable than other fighters.
  
  Thrust vectoring [...] works automatically in response to commands
  from the pilot.