Code :
import java.util.*;
public class Swap{
public static void main(String args[]){
int a, b;
Scanner sc = new Scanner(System.in);
System.out.println("Enter two values for swapping :");
a = sc.nextInt();
b = sc.nextInt();
System.out.println("The values of a & b before swapping : a = "+a+" b = "+b);
// main part of the code..
a = a + b;
b = a - b;
a = a - b;
System.out.println("The values of a & b after swapping : a = "+a+" b = "+b);
sc.close();
}
}
/* Explanation : Suppose a = 1 and b = 2 -> before swapping
Now, a = a + b = 1 + 2 = 3 => a = 3
b = a - b = 3 - 2 = 1 => b = 1
a = a - b = 3 - 1 = 2 => a = 2
a = 2 and b = 1 after swapping..
*/
-------------------------------------------------------------------------------
Thanks for watching..
Plz do subscribe, like and share..
For any query, plz comment in the comment section below..
Use Headphone or Earphone for better hearing of audio..
--------------------------------------------------------------------------------------
Video Link To Set Path For Java in Windows :
• How To Set Path For Java in Windows - For ...
-------------------------------------------------
Follow On :
✅Instagram : / computer_analyst.yt
✅Google+ : https://plus.google.com/b/11676538144...
✅Twitter : / yt_c_analyst
Nesta página do site você pode assistir ao vídeo on-line Java Program To Swap The Values Of Two Variables Without Using Third Variable - For Beginners duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Computer Analyst 04 Novembro 2017, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 57 vezes e gostou 2 espectadores. Boa visualização!