국비지원/백엔드

230313 알고리즘 - 데이터 교환 스와핑

선SEON 2023. 3. 13. 12:18

알고리즘

 

데이터 교환 스와핑

 

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var a = 10;
        var b = 20;

        var temp = a;
        a = b;
        b = temp;

        document.write('A=', a, ', B=', b);

    </script>
</body>
</html>

Java

package com.study.alg;

public class Test {
    public static void main(String[] ar){
        System.out.println("test");
        System.out.println("==============");
        int a = 10;
        int b = 20;
        System.out.printf("%d %d\n", a, b);
    }
}

Python

a=10
b=20
tmp = a
a = b
b = tmp
print('A=', a, ', B=', b)
a = 10
b = 20
a, b = b, a
print('A=', a, ', B=', b)