Web Analytics Made Easy -
StatCounter How to Swap two numbers without using third variable in Java? - CodingForum

Announcement

Collapse
No announcement yet.

How to Swap two numbers without using third variable in Java?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Swap two numbers without using third variable in Java?

    How to Swap two numbers without using third variable in Java?

  • #2
    public class swapping
    {
    public static void main(string args[])
    {
    int x = 10;
    int y = 20;
    System.out.println("Before swap:");
    System.out.println("x value: "+x);
    System.out.println("y value: "+y);
    x = x+y;
    y=x-y;
    x=x-y;
    System.out.println("After swap:");
    System.out.println("x value: "+x);
    System.out.println("y value: "+y);
    }
    }

    Comment

    Working...
    X