Skip to content

simple java program to swap two numbers without using a temp variable

Notifications You must be signed in to change notification settings

bazkennedy/SwapNumbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

17f464b · Dec 7, 2013

History

3 Commits
Dec 7, 2013
Dec 7, 2013
Dec 7, 2013
Dec 7, 2013

Repository files navigation

SwapNumbers

simple java program to swap two numbers without using a temp variable

The simplest method to swap two variables is to introduce a third or temp variable. This isn't the most ideal scenario as it takes up another space in your computers memory. This program takes two numbers (A and B). It adds the values of A and B and saves them in A. B is then substracted from A and stored in B. Finaly B is substracted from A and stored in A

a = 3; b = 5;

a = a + b;

a = 8; b = 3;

b = a - b;

a = 8 b = 3

a = a - b;

a = 5; b = 3;

About

simple java program to swap two numbers without using a temp variable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages