Sunday 8 June 2014

Program to swap two variables by using third variable

// this programs swaps the values of two variables a and b by using a third variable c;

public class swap 
{
public static void main(String[] args)
{
int a,b,c;
a=5;
b=3;
c=a;
a=b;
b=c;
System.out.print("a = "+a);
System.out.println("b = "+b);

}

}

output:
a=3
b=5

No comments:

Post a Comment

SAY HELLO!!