Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2016
    Location
    Bhopal , Madhya pradesh
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

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

  2. #2
    New Coder
    Join Date
    Sep 2016
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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);
    }
    }


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •