Write a program to initialize two integer variables a and b with 5 and 6 respectively and interchange them. Thus after interchanging a and b will be 6 and 5 respectively.
Answers
Answered by
32
Hey there!
♣ Program to initialize two integer variables a and b with 5 and 6 respectively and interchange them. Thus after interchanging a and b will be 6 and 5 respectively.
class Swapping
{
static void main()
{
int a=5,b=6,t;
System.out.println("Before Interchanging a="+a+" b="+b);
//Swapping the values
t=a;
a=b;
b=t;
System.out.println("After Interchanging a="+a+" b="+b);
}
}
Hope it helps You!
Answered by
26
public class interchange
{
public static void main()
{
int a =5, b=6;
int n;
n=a;
a=b;
b=n;
}
}
Similar questions