Java
{
Swapping using 3rd variable in JAVA
12 May
0
Write a program (WAP) in JAVA to read two numbers from keyboard(User Input) and exchanging the value of two variable(Swapping).
import java.util.Scanner;
class Sarthakmunds3
{
public static void main(String args[])
{
int a, b, temp;
System.out.println("Enter A and B :");
Scanner in = new Scanner(System.in);
a = in.nextInt();
b = in.nextInt();
System.out.println("Before Swapping :\nA = "+a+"\nB = "+b);
temp = a;
a = b;
b = temp;
System.out.println("After Swapping :\nA = "+a+"\nB = "+b);
}
}
Try it Yourself ➠
Must Read :-
Previous article
Next article
Leave Comments
Post a Comment