Answers for "swapping two variables without using third variable in java"

1

swap two variables without temporary java

import java.*; 
  
class noTemp { 
  
    public static void main(String a[]) 
    { 
        int x = 10; 
        int y = 5; 
        x = x + y; 
        y = x - y; 
        x = x - y; 
        System.out.println("After swaping:"
                           + " x = " + x + ", y = " + y); 
    } 
}
Posted by: Guest on January-22-2021
0

java swap variables

// a, b can be a numeric value
a += b; // a = a + b
b = a - b; // b = (a + b) - b = a  ---> b=a
a -= b; // a = (a + b) - (a) = b  ---> a=b
Posted by: Guest on April-28-2021

Code answers related to "swapping two variables without using third variable in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language