알고리즘/프로그래머스

[JAVA] 프로그래머스 Lv1. 가운데 글자 가져오기 - 다른 풀이

수진보배 2020. 10. 11. 19:36
728x90

class StringExercise{

    String getMiddle(String word){

        return word.substring((word.length()-1) / 2, word.length()/2 + 1);

    }

 

    ex) String word = "abcde";

            word.substring(2,3);  => "c"

    

         String word = "abcd";

            word.substring(1,3);  => "bc"

728x90