카테고리 없음

2018.03.12 수업내용

일등하이 2018. 5. 15. 21:20
반응형





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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] weapons2 = new string[4] { "대검""낡은검""도끼""지팡이" };
 
            // 확인할 아이템의 인덱스를 입력해주세요 >  [입력]
            // 숫자 0 => 대검
            // 숫자 1 => 낡은검
            // ...
            // 숫자 4... => 아이템을 찾을수 없습니다.
            // 끝 : 프로그램 종료 
 
            while (true)
            {
                Console.Write("확인할 아이템의 인덱스를 입력해주세요.");
                
                string command = Console.ReadLine();
                if (command == "끝")
                {
                    Console.Write("프로그램을 종료 합니다.");
                    break;
                }
                else
                {
                    int idx = -1;
                    bool canParse = int.TryParse(command, out idx);
                    if (canParse)
                    {
 
                        if (idx > 3)
                        {
                            Console.WriteLine("아이템을 찾을수 없습니다.");
                        }
                        else
                        {
                            Console.WriteLine(weapons2[idx] + "을 찾았습니다.");
                        }
 
                    }
                    else
                    {
                        Console.WriteLine("잘못된 입력 입니다.");
                    }
                }
            }
 
            Console.ReadKey();
        }
    }
}
 
cs

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
 
            //가방의 공간을 만든다 
            //아이템은 문자열 
 
            string[] inventory = new string[3] { """""" };
 
            Console.Write("가방에 넣을 아이템의 이름을 입력하세요.");
 
            string itemName = Console.ReadLine();
 
            inventory[0= itemName;
 
            for (int i = 0; i < inventory.Length; i++)
            {
                Console.WriteLine(i + " -> " + inventory[i]);
            }
 
            Console.Write("가방에 뺄 아이템의 인덱스를 입력하세요.");
 
            int idx;
            bool canParse = int.TryParse(Console.ReadLine(), out idx);
            if (canParse)
            {
                Console.WriteLine("====>" + idx);
                inventory[idx] = "";
            }
 
            for (int i = 0; i < inventory.Length; i++)
            {
                Console.WriteLine(i + " -> " + inventory[i]);
            }
 
            Console.ReadKey();
        }
    }
}
 
cs



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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
 
            string[] arrClassName = new string[4]{ "전사""마법사""도적"null };
            // 0: 전사, 1: 마법사, 2: 도적
            // 0: 도검, 1: 지팡이, 2: 단검
            // 배열로 선언하고 해당 인덱스를 입력 받아 직업을 출력 하세요.
 
            // 직업을 선택해주세요 (0~2) : [입력]
            // 0 : 전사를 선택 하셨습니다. 도검을 지급 받으셨군요...
            // 4 : 선택 할수 없는 직업 입니다. 다시 선택 해주세요.
 
            Console.ReadKey();
 
        }
    }
}
 
cs


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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arrStudentName = new string[3]{ "홍길동""임꺽정""장상욱" };
            string[] arrSubjectName = new string[3] { "국어""수학""과학" };
            //국어 , 수학, 과학 성적을 입력 받아 총 점수를 출력 해보세요.
            //Array.Sort 를 통해 정렬도 해보세요.
            int[] arrScore1 = new int[3];   //국어
            int[] arrScore2 = new int[3];   //수학
            int[] arrScore3 = new int[3];   //과학
            int[] arrScore4 = new int[3];   //총점
            int[] arrScore5 = new int[3];   //평균
 
            for (int i = 0; i < 3; i++)
            {
                Console.Write(arrStudentName[i] + "의 [" + arrSubjectName[0+ "] " + "성적을 입력해주세요.");
                arrScore1[i] = int.Parse(Console.ReadLine());
            }
 
            for (int i = 0; i < 3; i++)
            {
                Console.Write(arrStudentName[i] + "의 [" + arrSubjectName[1+ "] " + "성적을 입력해주세요.");
                arrScore2[i] = int.Parse(Console.ReadLine());
            }
 
            for (int i = 0; i < 3; i++)
            {
                Console.Write(arrStudentName[i] + "의 [" + arrSubjectName[2+ "] " + "성적을 입력해주세요.");
                arrScore3[i] = int.Parse(Console.ReadLine());
            }
 
            for (int i = 0; i < 3; i++)
            {
                arrScore4[i] = arrScore1[i] + arrScore2[i] + arrScore3[i];
                arrScore5[i] = arrScore4[i] / arrSubjectName.Length;
            }
            
            
 
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("이름: " + arrStudentName[i] + " , 국어: " + arrScore1[i] + " , 수학: " + arrScore2[i] + " , 과학: " + arrScore3[i] + " , 총점: " + arrScore4[i] + " , 평균: " + arrScore5[i]);
            }
 
            Console.ReadKey();
 
        }
    }
}
 


반응형