본문 바로가기

   
Programming/C#

두수를 Swap 하여 각형태로 출력

반응형

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace Source

{

    class Program

    {

        static void Main(string[] args)

        {

            /*

                       문제 1.

                        - 두수를 Swap해서 출력하는 메서드를 생성하시오

 

                       출력 ] 이전 : 5, 10

                              이후 : 10, 5

 

                       조건] 1. int, int

                             2. double, double

                             3. string, string

                             4. bool, bool

                             5. char, char

                             ** 메서드 이름은 모두 Swap

                             ** 5가지 모두 예를 드시오.

                             콜바이밸류

 

 

                       실행) Swap(10, 5);

                             Swap(true, false);

                             Swap(10.5, 2.4);

                             Swap("하하하", "호호호");

                             Swap('A', 'Z');                               

           */

            int a = 5;

            int b = 10;

            Swap(5, 10);

            Console.WriteLine("이전{0} 이후{1}", a, b);

            Swap(a, b);

            Swap(2.14, 2.54);

            Swap("a", "b");

            Swap(true, false);

            Swap('d', 'e');

            Console.ReadLine();

        }

 

        public static void Swap(int a, int b)

        {

            int temp;//빈컵

 

            temp = a;

            a = b;

            b = temp;

            Console.WriteLine("이전{0} 이후{1}", a, b);

        }

 

        public static void Swap(double a, double b)

        {

            double temp;//빈컵

 

            temp = a;

            a = b;

            b = temp;

            Console.WriteLine("이전{0} 이후{1}", a, b);

        }

 

        public static void Swap(string a, string b)

        {

            string temp;//빈컵

 

            temp = a;

            a = b;

            b = temp;

            Console.WriteLine("이전{0} 이후{1}", a, b);

        }

 

        public static void Swap(bool a, bool b)

        {

            bool temp;//빈컵

 

            temp = a;

            a = b;

            b = temp;

            Console.WriteLine("이전{0} 이후{1}", a, b);

        }

 

 

        public static void Swap(char a, char b)

        {

            char temp;//빈컵

 

            temp = a;

            a = b;

            b = temp;

            Console.WriteLine("이전{0} 이후{1}", a, b);

        }

    }   

}

 


반응형