2일차 구구단 중에 원하는 단을 입력해주세요. FormatException 에러
Console Programming/C# Console 2019. 9. 19. 14:39구구단 중에 원하는 단을 입력받고, 그 단을 출력하는 프로그램이다.
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax02
{
class Program
{
static void Main(string[] args)
{
Console.Write("구구단중에 원하는 단을 입력해주세요. ");
string input = Console.ReadLine();
int num = Convert.ToInt32(input);
for (int i = 1; i < 10; i++)
{
Console.WriteLine($"{num} x {i} = {num * i}");
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
입력받은 문자열을 Convet.ToInt32를 이용하여 정수로 바꿨다.
실행결과
디버그를 눌러보면 다음과 같은 화면이 나타난다.
입력된 문자열의 형식이 잘못되었을 때의 예외를 처리하지 않았다.
'Console Programming > C# Console' 카테고리의 다른 글
구구단 출력 (0) | 2019.09.20 |
---|---|
2일차 구구단 중에 원하는 단을 입력해주세요. FormatException 에러 해결 (0) | 2019.09.19 |
2일차 ***별찍기2*** (0) | 2019.09.19 |
2일차 ***별찍기1*** (0) | 2019.09.19 |
2일차 *** 구구단 2단 *** 출력 (0) | 2019.09.19 |