[Programmers] 가운데 글자 가져오기 - 연습문제

동민·2021년 3월 10일
0
// 가운데 글자 가져오기 - 연습문제
public class CenterStr {
	public String solution(String s) {
		return (s.length() % 2 == 1) ? s.substring(s.length() / 2, s.length() / 2 + 1)
				: s.substring(s.length() / 2 - 1, s.length() / 2 + 1);
	}

	public static void main(String[] args) {
		CenterStr s = new CenterStr();
		System.out.println(s.solution("hello"));
		System.out.println(s.solution("helloworld"));

	}
}
profile
BE Developer

0개의 댓글