package com.javatraineronline; public class SwapNumber { public static void swap(int a, int b) { // Assigning 'a' value to 'temp' int temp = a; // Assigning 'b' value to 'a' a = b; // Assigning 'temp' value to 'b' b = temp; // Printing before swapping System.out.println("After Swapping A : "+a+" B: "+b); } public static void main(String[] args) { // Declaring the 'a' and 'b' variable int a = 10; int b = 20; // Printing before swapping System.out.println("Before Swapping A : "+a+" B: "+b); // Calling Swapping Method. swap(a, b); } }
[su_box title=”Output for SwapNumber.java”]Before Swapping A : 10 B: 20 ..
After Swapping A : 20 B: 10 ..
[/su_box]
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet