728x90
SMALL

public class Solution {
    public string solution(int a, int b) {
        string answer = "";
        int[] month = new int[13] {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int days = b;
        //31 29 31 30 31 30 31 31 30 31 30 31
        
        for(int i=0;i<a;i++)
        {
             days += month[i];
        }
        
        if(days%7 == 1)
        {
            answer = "FRI";
        }
        else if(days%7 == 2)
        {
            answer = "SAT";
        }
        else if(days%7 == 3)
        {
            answer = "SUN";
        }
        else if(days%7 == 4)
        {
            answer = "MON";
        }
        else if(days%7 == 5)
        {
            answer = "TUE";
        }
        else if(days%7 == 6)
        {
            answer = "WED";
        }
        else if(days%7 == 0)
        {
            answer = "THU";
        }
        
        return answer;
    }
}

 

 

//////

 

 

using System;

public class Solution {
    public string solution(int a, int b) {
       string answer = "";

            DateTime dateValue = new DateTime(2016,a,b);
            answer = dateValue.DayOfWeek.ToString().Substring(0,3).ToUpper();

            return answer;
    }
}

 

 

 

using System;

public class Solution {
    public string solution(int a, int b) {
        string answer = "";

        string[] dayOfTheWeek = new string[7]{"SUN","MON","TUE","WED","THU","FRI","SAT"};
        int[] daysOfMonth = new int[12]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int totalDays = 5; //1월 1일이 금요일 이라서 초기화를 5로 시킨다.
        
        for(int i = 0 ; i < a - 1 ; i++)
        {
            totalDays += daysOfMonth[i];
        }

        totalDays += b - 1;
        answer = dayOfTheWeek[totalDays%7];

        return answer;
    }
}

 

 

////////////////

자바

 

 

 

class Solution {
  public String solution(int a, int b) {
      String answer = "";

      int[] c = {31,29,31,30,31,30,31,31,30,31,30,31};
      String[] MM ={"FRI","SAT","SUN","MON","TUE","WED","THU"};
      int Adate = 0;
      
      for(int i = 0 ; i< a-1; i++)
      {
          Adate += c[i];
      }
      
      Adate += b-1;
      answer = MM[Adate %7];

      return answer;
  }
}

 

 

 

import java.time.*;
class Solution {
  public String solution(int a, int b) {
      return LocalDate.of(2016, a, b).getDayOfWeek().toString().substring(0,3);
  }
}

 

 

 

import java.time.*;

class TryHelloWorld
{
    public String getDayName(int a, int b)
    {
       LocalDate date = LocalDate.of(2016, a, b);
       return date.getDayOfWeek().toString().substring(0, 3);
    }
    
    public static void main(String[] args)
    {
        TryHelloWorld test = new TryHelloWorld();
        int a=5, b=24;
        System.out.println(test.getDayName(a,b));
    }
}
728x90

설정

트랙백

댓글