30. 문자 반복 출력하기

김해준's avatar
Dec 04, 2025
30. 문자 반복 출력하기
문제
notion image
풀이
class Solution { public String solution(String my_string, int n) { String answer = ""; for(int i = 0 ; i < my_string.length();i++) { for(int j = 0 ; j < n; j++) { answer += my_string.charAt(i); } } return answer; } }
notion image
my_string.length() : 해당 문자열의 길이를 반환
my_string.charAt(i) : 해당 문자열의 i번째 글자를 반환
문자열은 + 시 결합 연산자로 처리되기에 +를 사용해서 문자열 끼리 붙일 수 있음
Share article