본문 바로가기

C#/수업내용

2020-04-03 Source

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_002
{
    class App
    {
        public App()
        {
 
            //반복문
 
            /*       
                    string name1 = "홍길동";     
 
                    //Console.WriteLine(DateTime.Today.ToShortDateString());
 
                    for (int i = 1; i < 6; i++) {
                        Console.WriteLine("{0}님이 줄넘기를 {1}회 했습니다.",name1,i);
            */
 
            /*
                    string heroName = "아이언맨";
                    string enemyName = "타노스";
 
                    int heroMaxHP = 10;
                    int enemyDamage = 3;
 
                    Console.WriteLine("{0}의 체력은 {1}입니다.", heroName, heroMaxHP);
                    Console.WriteLine("{0}의 공격력은 {1}입니다.\n", enemyName, enemyDamage);
 
                    for (int i = 0; i < 4; i++)
                    {
                        heroMaxHP -= enemyDamage;
                        Console.WriteLine("{0}이 {1}에게 {2}의 공격을 받았습니다.", heroName, enemyName, enemyDamage);
                        Console.WriteLine("{0}의 체력은 {1}입니다.\n", heroName, heroMaxHP);
                    }
                    */
            /*
                string name = "홍길동";
                string food = "빵";
                int num = 5;
 
                Console.WriteLine("{0}의 갯수는 {1}개 입니다.\n", name, num);
 
                for (int i = num-1; i > -1; i--) {
                    Console.WriteLine("{0}님이 {1}을 먹었습니다.", name, food);
                    Console.WriteLine("{0}개의 {1}이 남았습니다.\n", i, food);
                }
                */
            /*
        int a, b;
 
        for (a = 2; a < 3; a++) {
            for (b = 1; b < 10; b++) {
                Console.WriteLine("{0} x {1}",a,b);
              }
        }
        */
            /*
                int a, b;
 
                for (a = 2; a < 3; a++)
                {
                    for (b = 1; b < 10; b++)
                    {
                        Console.WriteLine("{0} x {1} = {2}", a, b, a*b);
                    }
                }
    */
            /*
                           for (int a = 1; a < 13; a++)
                           {
                               Console.WriteLine("{0}월",a);
                           }
           */
            /*
             for (int a = 2018; a < 2025; a++)
             {
                 Console.WriteLine("{0}년", a);
             }
             */
 
 
            /*
            //색입히기
            string name = "홍길동";
            int MaxHP = 10;
            int PreHP = 10;
            int MonsterDamage = -3;
            int potion = 1;
 
            
 
            Console.WriteLine("캐릭터 이름 : {0}", name);
            Console.WriteLine("최대 체력 : {0}", MaxHP);
            Console.WriteLine("현재 체력 : {0}\n", PreHP);         
 
            for (int i = 0; i < 3; i++) {
 
                PreHP += MonsterDamage;
                Console.Write("공격을 받았습니다 ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("({0}) ", MonsterDamage);
                Console.ResetColor();
                Console.WriteLine("{0}/{1}", PreHP, MaxHP);
                PreHP += potion;
 
                Console.Write("물약을 먹고 체력을 회복했습니다 ");
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("(+{0})",potion);
                Console.ResetColor();
                Console.WriteLine(" {0}/{1}\n",PreHP, MaxHP);
 
            }
    */
            /*    
                    Console.Write("당신이 좋아하는 과일은 무엇인가요?");
                    string input = Console.ReadLine();
                    Console.WriteLine(input + "를 좋아하시는군요!");
            
 
            string applesInBasket = "12";
            
            int total = Convert.ToInt32(applesInBasket);
 
            Console.WriteLine(total+4);
             */
 
            /*
                        Console.Write("출력 하고싶은 구구단의 단수를 입력해주세요. : ");
                        string input = Console.ReadLine();
                        int gugudan = Convert.ToInt32(input);
 
                            for (int b = 1; b < 10; b++) {
                                Console.WriteLine("{0} X {1} = {2}", gugudan, b, gugudan * b);
                           }
 
            */
 
            /*
            Console.Write("영웅의 이름은 무엇입니까? ");
            string heroName = Console.ReadLine();
 
            Console.Write("영웅의 공격력은 몇입니까? ");
 
            Console.Write("몬스터의 체력은 몇입니까? ");
            string input2 = Console.ReadLine();
            int monsterMaxHp = Convert.ToInt32(input2);
 
 
            Console.Write("몬스터를 몇회 공격 하시겠습니까? ");
 
            string input3 = Console.ReadLine(); // 강사님이 하신 문자열 자르기
            char sp = '회';
            string[] spstring = input3.Split(sp);
            int num = Convert.ToInt32(spstring[0]);
 
            //string input3 = Console.ReadLine(); //내가 찾은 문자열 입력값을 구분자로 자르기
            //string[] result = input3.Split(new char[] { '회' }); 
            //int num = Convert.ToInt32(result[0]);
 
 
            int monsterHp = monsterMaxHp;
 
            for (int i = 0; i < num; i++)
            {
                monsterHp -= heroDamage;
                Console.WriteLine("영웅이 몬스터를 공격 했습니다 ({0}/{1})", monsterHp, monsterMaxHp);
            }
            */
 
            //조건문
 
            /*
            int count = 0;
 
            for (int i = 0; i < 10; i++) {
                if (i == 5) {
                    count = i;
                    break;  // break 점프문
                }
                Console.WriteLine("줄넘기를 {0}회 했습니다.", i + 1);     
            }
            Console.WriteLine("줄넘기 {0}회 완료!", count);
            */
 
            /*
                       for (int i = 0; i < 10; i++)
                       {
                           if (i < 6)
                           {
                               continue; //continue 점프문
                           }
                           Console.WriteLine("줄넘기를 {0}회 했습니다.", i+1);
                       }
             */
 
 
            //이중반복문
 
            /*
            for (int i = 0; i < 3; i++) {
 
                for (int j = 0; j < 3; j++) {
                    Console.WriteLine("홍길동");
                }
                Console.WriteLine("\r");
            }
            */
 
            /*
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Console.Write("*");
                }
                Console.Write("\n");
            }
            */
 
            /*
             * 
            for (int i = 1; i < 6; i++)
            {
                for (int j = 1; j < i+1; j++)
                {
                    Console.Write("*");                
                }
                Console.Write("\n");
            }
            */
 
            /*
 
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5-i; j++)
                {
                    Console.Write("*");
                }
                Console.Write("\n");
            }
 
            */
 
 
            int num = 5;
 
            for (int i = 0; i < num; i++)
            {
                for (int j = num - 1; j > i; j--)
                {
                    Console.Write(" ");
                }
 
                for (int j = 0; j < 2 * i + 1; j++)
                {
                    Console.Write("*");
                }
                Console.Write("\n");
            }
 
 
        }
    }
}
 
 
 
 

'C# > 수업내용' 카테고리의 다른 글

2020-04-08 수업내용 Source  (0) 2020.04.08
2020-04-07 수업내용 Source  (0) 2020.04.07
2020-04-07 if문 예제 문제.  (0) 2020.04.07
2020-04-06 Source  (0) 2020.04.06
2020-04-03  (0) 2020.04.03