How do you swap two numbers without using a third variable in Java?

Pubblicato il: 08 agosto 2023
sul canale di: The Disciplined learner
138
5

Top 50 Java Programming Interview Questions
public static void main(String[] args) {
int x,y;
System.out.println("Please Enter x and y");
Scanner in=new Scanner(System.in);
x=in.nextInt();
y=in.nextInt();
System.out.println("Before Swap \nx = "+x+"\ny = "+y);
x=x+y;
y=x-y;
x=x-y;
System.out.println("After Swap \nx = "+x+"\ny = "+y);
}


In questa pagina del sito puoi guardare il video online How do you swap two numbers without using a third variable in Java? della durata di ore minuti seconda in buona qualità , che l'utente ha caricato The Disciplined learner 08 agosto 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 138 volte e gli è piaciuto 5 spettatori. Buona visione!