Swap3.java
Aim:
To swap two numbers
Source code:
import java.lang.*;
import java.util.*;
class Swap3
{
public static void main(String args[])
{
int a,b,t;
Scanner input=new Scanner(System.in);
System.out.println("Enter values for a,b");
a=input.nextInt();
b=input.nextInt();
System.out.println("before swapping: a="+a+"b="+b);
t=a;
a=b;
b=t;
System.out.println("after swapping: a="+a+"b="+b);
}
}
Output:
Enter values for a,b
10
20
before swapping: a=10b=20
after swapping: a=20b=10
No comments:
Post a Comment