코딩/프로그래머스

[프로그래머스] Java - 문자 반복 출력하기 ❗

유미._. 2023. 9. 4. 19:45
728x90

 

문제 설명

 

문자열 my_string과 정수 n이 매개변수로 주어질 때, my_string에 들어있는 각 문자를 n만큼 반복한 문자열을 return 하도록 solution 함수를 완성해보세요.

 

 

 

나의 코드 풀이

 

class Solution {
    public String solution(String my_string, int n) {
        String result = "";
        
        for (int i = 0; i < my_string.length(); i++) {
			for (int j = 0; j < n; j++) {
				result += my_string.charAt(i);
			}
		}
        return result;
    }
}

 

 

다른 사람의 풀이

 

 

 

728x90
반응형