Console Programming/C# Console
9일차 메서드의 정의(2) -홀수,짝수 반환
폰타인
2019. 10. 1. 09:58
정수 1개를 전달하면 그수가 홀수면 "홀수"문자열을 짝수면 "짝수"라는 문자열을
반환하는 메서드를 정의/호출
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
|
using System;
using Syntax24;
namespace Syntax24
{
class App
{
public App()
{
Console.WriteLine("2019-09-30");
Console.WriteLine();
string str = OddOrEven(5);
Console.WriteLine(str);
}
public string OddOrEven(int n)
{
string result = "";
if (n % 2 == 0)
{
result = "짝수";
}
else
{
result = "홀수";
}
return result;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|