1. implement two variable value exchanges:
public static void main (String[] args) { int a = 3; int b = 5; int temp = a; a = b; b = temp; System.out.println (a); system.out.println (b); system.out.println ("----------------"); a = a + b; b = a - b; a = a - b; sYstem.out.println (a); system.out.println (b); }
The above code is when a and b variable values are interchanged, two ways are implemented: one is to use temporary variables, and the other is to take advantage of the addition and subtraction of two variables without resorting to temporary variables.
2.
Public class swaptest2 { public static void change (char[] cs, char c) { cs[0] = ' C '; c = ' D '; } public static void swap (CHAR[] CS) { char temp = cs[0]; cs[0] = cs[1]; cs[1] = temp; } Public static void main (String[] args) { char[] ch = {' A ', ' B '}; swap (CH);        SYSTEM.OUT.PRINTLN (CH); change (ch, ch[1]); SYSTEM.OUT.PRINTLN (ch); }}
Java is a value pass, and for an array, the first address of the array is passed. The use of arrays allows for value exchange.
Java Record -32-value Exchange