Q. Write a simple program to swap the numbers.
Like if we have –
a=20;
b=30;
I want a=30; and b=20;
SOLUTION :-
package p1;
public class SwapNumbers {
public static void main(String[] args) {
int a=20;
int b=30;
System.out.println("Before swapping:a:"+a+",b:"+b);
int temp = a;
a=b;
b=temp;
System.out.println("After swapping:a:="+a+", b:"+b);
}
}
Leave a Reply