Generally, the exchange between the two variables should be used in the third variable. This is OK, but the creation of a new variable has increased system overhead. If the two integer variables to be exchanged, you can use more efficient methods. For example:^(different or) operation, for example, as follows:
Import Java.util.Scanner; Public Class VariableExchange {Public Static Void Main (String ARGS []) {Scanner Scan = New Scanner (System.in); ln ("Please enter the first integer variable:") ; Long a = scan.nextlong (); System.out.println ("Please enter the second integer variable:"); Long b = scan.nextlong (); system.out.println ("a ="+a+" /tb = "+b); System.out.println (" After the variable is switched ... "); a = a^b; // Perform variable swap b = b^a; a = a; ^B; System.out.println ("a ="+a+"/tb ="+b);}}
Output results:
Run: Please enter the first integer variable: 100, please enter the second integer variable: 200 a = 100 b = 200 After the variable is switched ... A = 200 b = 100 buccesful (Total Time: 5: 5 SECONDS)