Java Tutorial
- Runtime
- java 21.0.12
- Files
- 60 files · 24 KB
- Runs
- 50 runs
- Published
package sessionFour;/* Swap two int variables using third variable. Then do it without third variable*/public class SwapTwoIntVariables { public static void main(String[] args) { int a = 1, b = 2; int temp; temp = a; a = b; b = temp; System.out.println("A: " + a + " & B: " + b); // Without third variable int c = 5, d = 9; c = c + d; // c = 14; d = c - d; // d = 5; c = c - d; // c = 9; System.out.println("C: " + c + " & D: " + d); }}