7일차 Switch 문의 사용 (4)
Console Programming/C# Console 2019. 9. 26. 09:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
using System;
namespace Syntax20
{
class Program
{
static void Main(string[] args)
{
int input = int.Parse(Console.ReadLine());
switch (input)
{
case 1:
{
Console.WriteLine(31);
break;
}
case 3:
{
Console.WriteLine(31);
break;
}
case 5:
{
Console.WriteLine(31);
break;
}
case 7:
{
Console.WriteLine(31);
break;
}
case 8:
{
Console.WriteLine(31);
break;
}
case 10:
{
Console.WriteLine(31);
break;
}
case 12:
{
Console.WriteLine(31);
break;
}
case 4:
{
Console.WriteLine(30);
break;
}
case 6:
{
Console.WriteLine(30);
break;
}
case 9:
{
Console.WriteLine(30);
break;
}
case 11:
{
Console.WriteLine(30);
break;
}
case 2:
{
Console.WriteLine(28);
break;
}
case 15:
{
Console.WriteLine(-1);
break;
}
default:
{
break;
}
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
선택지의 개수가 많아지면 switch 문의 작성이 번거로워진다.
같은 결과를 케이스들은
case 1:
case 3:
이런식으로 묶어서 쓸 수 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
using System;
namespace Syntax20
{
class Program
{
static void Main(string[] args)
{
int input = int.Parse(Console.ReadLine());
switch (input)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
Console.WriteLine(31);
break;
}
case 4:
case 6:
case 9:
case 11:
{
Console.WriteLine(30);
break;
}
case 2:
{
Console.WriteLine(28);
break;
}
case 15:
{
Console.WriteLine(-1);
break;
}
default:
{
break;
}
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'Console Programming > C# Console' 카테고리의 다른 글
7일차 switch문의 사용 (6) (0) | 2019.09.26 |
---|---|
7일차 switch문의 사용 (5) (0) | 2019.09.26 |
7일차 switch 문의 사용 (3) (0) | 2019.09.26 |
7일차 switch문의 사용 (2) (0) | 2019.09.26 |
7일차 switch문의 사용 (0) | 2019.09.26 |