Swap two numbers without using third variable (A java Program)

Pubblicato il: 06 settembre 2020
sul canale di: Knowledge Circle
1,351
104

Dear viewers,
In this video , I will thoroughly explain how to swap(Interchange) the values of two variables without declaring any extra variable.

Code-👇

import java.util.Scanner;
class swap
{
public static void main (String[ ] args)
{
Scanner sc=new Scanner (System.in);
int a,b;
System.out.println("Enter first number");
a=sc.nextInt();
System.out.println("Enter first number");
b=sc.nextInt();
System.out.println("Numbers before swapping");
System.out.println("a="+a);
System.out.println("b="+b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("Numbers after swapping");
System.out.println("a="+a);
System.out.println("b="+b);
}
}


#javaprograms
#swaptwonumbers



Follow me on Instagram 👇

  / vinay_k_jaiswal  

Follow me on facebook 👇

  / vkj21  

Follow me on twitter 👇

  / vinaykumarsmart  


In questa pagina del sito puoi guardare il video online Swap two numbers without using third variable (A java Program) della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Knowledge Circle 06 settembre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,351 volte e gli è piaciuto 104 spettatori. Buona visione!