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]

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *