  The inclusive J/$\psi$ production has been studied in Pn-Pb and pp collisions
at the centre-of-mass energy per nucleon pair $\sqrt{s_{\rm NN}}=5.02$ TeV,
using the ALICE detector at the CERN LHC. The J/$\psi$ meson is reconstructed,
in the centre-of-mass rapidity interval $2.5<y<4$ and in the
transverse-momentum range $p_{\rm T}<12$ GeV/$c$, via its decay to a muon pair.
In this Letter, we present results on the inclusive J/$\psi$ cross section in
pp collisions at $\sqrt{s}=5.02$ TeV and on the nuclear modification factor
$R_{\rm AA}$. The latter is presented as a function of the centrality of the
collision and, for central collisions, as a function of the transverse momentum
$p_{\rm T}$ of the J/$\psi$. The measured $R_{\rm AA}$ values indicate a
suppression of the J/$\psi$ in nuclear collisions and are then compared to our
previous results obtained in Pb-Pb collisions at $\sqrt{s_{\rm NN}}=2.76$ TeV.
The ratio of the $R_{\rm AA}$ values at the two energies is also computed and
compared to calculations of statistical and dynamical models. The numerical
value of the ratio for central events (0-10\% centrality) is $1.17 \pm 0.04
{\rm{(stat)}}\pm 0.20 {\rm{(syst)}}$. In central events, as a function of
$p_{\rm T}$, a slight increase of $R_{\rm AA}$ with collision energy is visible
in the region $2<p_{\rm T}<6$ GeV/$c$. Theoretical calculations provide a good
description of the measurements, within uncertainties.
