Wednesday 26 February 2014

Tagged Under:

Java program to swap two numbers without using temp variable

Share














Source Code

class Swapvariable

{

 public static void main(String s[])

 {

  int x,y;

  x=Integer.parseInt(s[0]);

  y=Integer.parseInt(s[1]);

  System.out.println("\nBefore Swap:\n"+"a="+x+"\tb="+y);

  x=x+y;

  y=x-y;

  x=x-y; 

  System.out.println("\nAfter Swap:\n"+"a="+x+"\tb="+y);

 }

}

Output


0 comments:

Post a Comment

Contact Us

Want to ask anything? Be our guest, give us a message.

Name Email * Message *