c#/복습

(재연습) switch, while

yeeendy 2023. 1. 21. 23:51

교재 있는 내용 연습

<switch>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study0121
{
    class App
    {
        
        //생성자
        public App()
        {
            int number = 1;
            switch (number)
            {
                case 1:
                    Console.WriteLine("하나");
                    break;
                case 2:
                    Console.WriteLine("둘");
                    break;
                case 3:
                    Console.WriteLine("셋");
                    break;
                default:
                    Console.WriteLine("예외사항입니다.");
                    break;
            }
            
        }

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study0121
{
    class App
    {
        
        //생성자
        public App()
        {
            Console.Write("요일을 입력하세요.(일,월,화,수,목,금,토) : ");
            string day = Console.ReadLine();

            switch (day)
            {
                case "일":
                    Console.WriteLine("Sunday");
                    break;
                case "월":
                    Console.WriteLine("Monday");
                    break;
                case "화":
                    Console.WriteLine("Tuesday");
                    break;
                case "수":
                    Console.WriteLine("Wednesday");
                    break;
                case "목":
                    Console.WriteLine("Thursday");
                    break;
                case "금":
                    Console.WriteLine("Friday");
                    break;
                case "토":
                    Console.WriteLine("Saturday");
                    break;
                default:
                    Console.WriteLine($"{day}는 요일이 아닙니다.");
                    break;
            }
            
        }

    }
}

<while>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study0121
{
    class App
    {
        
        //생성자
        public App()
        {
            int a = 10;
            while (a > 0)
            {
                Console.WriteLine(a--);
            }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study0121
{
    class App
    {
        
        //생성자
        public App()
        {
            int a = 10;
            while (a > 0)
            {
                Console.WriteLine(a);
                a -= 2; //a = a - 2;
            }
        }

    }
}

'c# > 복습' 카테고리의 다른 글

(재연습)2차원 배열  (0) 2023.01.22
(재연습) 배열  (0) 2023.01.22
(재연습) 시즈탱크(탱크모드/공성모드)  (0) 2023.01.21
(재연습)클래스 연습  (0) 2023.01.21
(재연습)메서드 연습  (0) 2023.01.21