Language/C#
if ~ else
ninanio3
2011. 11. 12. 13:14
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
-
-
/*
-
* 문제 내용 : 입력된 정수가 짝수인지 홀수인지 알아보자.
-
* if ~ else 조건문을 익힌다.
-
* 조건식 내용이 참이면 if의 바디({})를 실행하고, 거짓이면 else의 바디({})를 실행한다.
-
* */
-
-
-
namespace Console_Test
-
{
-
public class Program
-
{
-
static void Main(string[] args)
-
{
-
Console.WriteLine("정수를 입력하세요");
-
int iNum1 = int.Parse(Console.ReadLine());
-
-
bool bIs = Number.isE(iNum1);
-
-
if (bIs)
-
{
-
Console.WriteLine("정수{0}는 짝수입니다.", iNum1);
-
}
-
else
-
{
-
Console.WriteLine("정수{0}는 홀수입니다.", iNum1);
-
}
-
}
-
-
public class Number
-
{
-
public static bool isE(int even)
-
{
-
if (even % 2 == 0)
-
{
-
return true;
-
}
-
else
-
{
-
return false;
-
}
-
}
-
}
-
}
-
}
이 문제의 출처는 c#프로그래밍 기본기 익히기, 정보문화사, 25000, 조효은지음, 2010년 10월 4일 2쇄발행, ISBN 978-89-5674-452-0 이고, 풀이는 제가 직접 썼습니다. 저작권 침해가 됐다면 내리겠습니다.