I'm having trouble writing this exercise in the Java Language, using the Eclipse IDE:
Read two values for the variables A and B, change the values so that the variable A has the value of the variable B and that the variable B has the value of the variable A. Display the values exchanged .
I know I need to declare Variable A, Variable B, and an Auxiliary Variable!
In this case I can only make Variable A get the value of Variable B! But Variable B presents the value itself and does not present the Value of A which is what I need!
MY CODE:
import java.io.IOException;
import java.util.Scanner;
public class Variavel {
public static void main(String[] args) throws IOException {
int VarA;
int VarB;
int Aux;
System.out.println("Digite a Primeira Variavel");
Scanner Lera = new Scanner(System.in);
VarA= Lera.nextInt();
System.out.println("Digite a Primeira Variavel");
VarB= Lera.nextInt();
VarA=VarB;
Aux=VarA;
VarB=Aux;
System.out.println("O valor de A é: " +VarB);
System.out.println("O valor de B é: " +Aux);
Lera.close();
}
}
NOTE: I'm at the beginning of JAVA Classes, so for now I only use the basic commands like INT, Scanner, Read? I have not yet learned FOR, WHILE, IF, ELSE
IMAGE OF RESULT