C#
210513 C#_switch문
S_pot
2021. 5. 31. 15:49
class Program
{
static void Main(string[] args)
{
Console.Write("1~3 숫자를 입력하세요 : ");
int Number = int.Parse(Console.ReadLine());
switch (Number)
{
case 1:
Console.WriteLine("일");
break; // break: switch문을 종료하라.
case 2:
Console.WriteLine("이");
break;
case 3:
Console.WriteLine("삼");
break;
default: // 해당하는 값이 없을 때 실행된다.
Console.WriteLine("잘 못 입력하셨습니다.");
break;
}
}
}

class Program
{
static void Main(string[] args)
{
Console.WriteLine("이번 달은 몇 월인가요: ");
int input = int.Parse(Console.ReadLine());
switch(input)
{
case 12: // case 다음에 break가 생략된 경우
case 1:
case 2:
Console.WriteLine("겨울입니다.");
break;
case 3:
case 4:
case 5:
Console.WriteLine("봄입니다.");
break;
case 6:
case 7:
case 8:
Console.WriteLine("여름입니다.");
break;
case 9:
case 10:
case 11:
Console.WriteLine("가을입니다.");
break;
default:
Console.WriteLine(" 대체 어떤 행성에 살고 계신가요?");
break;
}
}
}
