오늘은 switch~case문이에요.
using System;
namespace Test.Swirch.test1{
public class Calendar{
public bool IsYear(int year){
bool isCheck = false;
if (((year % 400 ==0) && (year % 100 != 0) )||(year % 400 ==0)){
isCheck = true; //400으로 나눈 나머지값이 0이거나 100으로 나눈나머지가 0이아닐경우 true로변경
}
return isCheck;
}
public int Day(int year,int month){
int toDay=0;
if (IsYear (year)){
swtich(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: toDay = 31; break; //month값이 12일경우 toDay에 31을 대입하고 순환문 빠져나옴
case 4:
case 6:
case 9:
case 11: toDay = 30;break; //month값이 30일경우 toDay에 31을 대입하고 순환문 빠져나옴
case 2: toDay = 29; break; //month값이 29일경우 toDay에 31을 대입하고 순환문 빠져나옴
}
}else{
swtich(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: toDay = 31; break;
case 4:
case 6:
case 9:
case 11: toDay = 30;break;
case 2: toDay = 28; break;
}
}
return toDay;
}
}
}
using System;
using Test.Swirch.test1;
namespace Test.Swirch.test2{
public class Program{
public static void Main(string[] args){
Console.WriteLine("년도와 달을 입력하세요");
Console.Write("년도: ");
int year = int.Parse(Console.ReadLine());
Console.Write("달: ");
int month = int.Parse(Console.ReadLine());
Calendar cal = new Calendar();
int day=Calendar.Day(year,month);
Console.WriteLine("{0}년 {1}월에는 {2}이 있습니다.",year,month,days);
}
}
}
#c# #switch~case #if문 #switch문
'코딩' 카테고리의 다른 글
비주얼스튜디오2017 디버그 모드 오류 -중단점이 현재~~- (0) | 2019.04.03 |
---|---|
C#에서 IP주소 확인 (0) | 2019.03.30 |
javascript 문자열 자르기,반대로 자르기,특정문자를 기준으로 자르기 (0) | 2019.03.23 |
C# break문 (0) | 2019.03.21 |
Visual Studio에서 디버그 실행시 오류 처리 (0) | 2019.03.19 |