How do you reverse the variables? [closed]

-7

Write a Java program with what is requested below.

A - Declare the variables X, Y, and Z of type int. B - Assign 10 to variable X. C - Assign 2 to variable Y. D - With the help of variable Z, reverse the values of X and Y. E - Print the values of the variables X, Y and Z respectively.

Obs. I'm starting the Java course now and I can not ask that question, can anyone help me?

    
asked by anonymous 26.05.2018 / 20:28

1 answer

-2

Try this:

public int X,Y,Z;

X = 10;
Y = 2;

//Inversão
Z = Y; //Z = 2
Y = X; //Y = 10
X = Z; //X = 2

//Assim inverteu-se os valores de X e Y
    
26.05.2018 / 20:31