본문 바로가기
Programmers/Level. 0

[프로그래머스, Java] 배열 원소의 길이

by baebaebae 2022. 12. 25.
728x90

문제 설명

문자열 배열 strlist가 매개변수로 주어집니다. strlist 각 원소의 길이를 담은 배열을 return하도록 solution 함수를 완성해주세요.

 

제한사항
  • 1 ≤ strlist 원소의 길이 ≤ 100
  • strlist는 알파벳 소문자, 대문자, 특수문자로 구성되어 있습니다.
 
입출력 예
strlist result
["We", "are", "the", "world!"] [2, 3, 3, 6]
["I", "Love", "Programmers."] [1, 4, 12]

 

 

class Solution {
    public int[] solution(String[] strlist) {
        int[] answer = new int[strlist.length];
        
        for(int i=0; i<strlist.length; i++){
            answer[i] = strlist[i].length();
        }
        
        return answer;
    }
}

 

728x90