Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 475 Bytes

File metadata and controls

23 lines (19 loc) · 475 Bytes

프로그래머스 Level1 : 연습문제 가운데 글자 가져오기

class Solution {
    public String solution(String s) {
        String answer = "";
        int index = 0;
        int l = s.length();
        
        if(l%2==0){
            index=l/2-1;
            answer = s.substring(index,index+2);
        } else{
            index=l/2;
            answer = s.substring(index,index+1);
        }
        
        return answer;
    }
}