ZTransform of a sequence that changes its explicit formula

Hi,
i was trying to calculate the Zeta-Transform of a sequence that changes its explicit formula, for example:

x(n)= n  for  n=2k
x(n) = 1/n for n=2k+1 

How could I do?

In this case there is a closed form for the input and ZTransform seems to handle it.

ZTransform[x^((-1)^n), n, z]

(* Out[342]= (z (1 + x^2 z))/(x (-1 + z^2)) *)

Thanks for replying,
so should i write as input:

ZTransform[x^((-1)^n), n, z] 
(* Out[342]= (z (1 + x^2 z))/(x (-1 + z^2)) *)

?
If i do so, Wolfram doesn’t compute it, trying to solve

342=(z (1 + x^2 z))/(x (-1 + z^2)) 

as an equation.
As example, how could I write this?

You need to read up on basic Mathematica syntax, and become familiar with the input/output formatting.

Also please see this
to understand how Mathematica formatting is done on this site. I showed both input and output in what is a very common and obvious manner, with the output enclosed in a Mathematica comment. How this became the above proposed input, while losing a final asterisk and thus that comment enclosure, escapes my understanding.

For the stated purposes it would be good to check Mathematica documentation on the function Piecewise and possibly also the UnitStep function. Either one can be used to handle the problem most recently posed.

ZTransform[UnitStep[n - 3]*n + UnitStep[2 - n], n, z]

(* Out[350]= (-1 + 2 z - z^3 + z^4)/((-1 + z)^2 z^2) *)

ZTransform[Piecewise[{{1, n < 3}}, n], n, z]

(* Out[349]= (-1 + 2 z - z^3 + z^4)/((-1 + z)^2 z^2) *)

Sorry for the post-format, but i had to write quite quickly.
Thank you very much for the reply, it really helped and solved the problem.