2일차 구구단 중에 원하는 단을 입력해주세요. FormatException 에러 해결

Console Programming/C# Console 2019. 9. 19. 15:09

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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace Syntax02

{

    class Program

    {

        static void Main(string[] args)

        {

            int num = -1;

            bool repeat = true;

 

            

 

            while (repeat)

            {

                Console.Write("구구단중에 원하는 단을 입력해주세요. ");

                string input = Console.ReadLine();

                try

                {

                    num = Convert.ToInt32(input);

                    if (num < Int32.MaxValue)

                    {

                        for (int i = 1; i < 10; i++)

                        {

                            Console.WriteLine($"{num} x {i} = {num * i}");

                        }

                    }

                    else

                    {

                        Console.WriteLine("num이 -2,147,483,648 and +2,147,483,647을 초과합니다.");

                    }

                }

                catch (FormatException)

                {

                    Console.WriteLine("입력된 문자열은 정수가 아닙니다.");

                }

                catch (OverflowException)

                {

                    Console.WriteLine("숫자가 Int32 규격에 맞지 않습니다.");

                }

                Console.Write("다시 하시겠습니까? (Y,N)");

 

                string go = Console.ReadLine();

                if (go.ToUpper() != "Y")

                {

                    repeat = false;

                }

 

            }

        }

    }

}

 

http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

 

: