배열원소의길이1 프로그래머스 0. 배열 원소의 길이 (자바) answer 배열에 new int[] 로 strlist.length 요소가 담긴 배열을 생성해준다. 그리고 strlist의 길이만큼 반복되는 반복문에서 i번 돌아갈 때마다 strlist의 i번째 요소의 길이가 answer 배열의 i 번째 인덱스에 들어가도록 식을 작성한다. 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; } } 2023. 9. 21. 이전 1 다음 728x90