How swap two number | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1
22nd Sep 2017, 7:36 AM
MUKESH KUMAR P
MUKESH KUMAR P - avatar
4 ответов
+ 10
the code playground is quite large by now you can search the word 'swap' and filter by any language available there https://code.sololearn.com/cHv1C8jEO6Rk/?ref=app https://code.sololearn.com/cbKT04Q8MRSm/?ref=app
22nd Sep 2017, 8:09 AM
Burey
Burey - avatar
+ 5
public class Program { public static void main(String[] args) { int a = 52; int b = 42; a ^= b; b ^= a; a ^= b; System.out.println(a); System.out.println(b); } }
22nd Sep 2017, 8:04 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thq,,, BT without use third variable means
22nd Sep 2017, 8:05 AM
MUKESH KUMAR P
MUKESH KUMAR P - avatar
0
we have to perform the program using only two variables X and Y and we can't use a temporary variable. That is:supposed x=1,y=2 then we can shift value of X in temporary variable say Z and put value of y in X and put value of z in y hence d no's will be interchanged this is using third variable which Z in this example
11th Nov 2017, 10:46 AM
Aanchal Saha
Aanchal Saha - avatar