프로그래머스/lv0
문자 반복 출력하기
do_it0904
2022. 12. 5. 09:59
/* 문자 반복 출력하기
* 문자열 my_string과 정수 n이 매개변수로 주어질 때,
* my_string에 들어있는 각 문자를 n만큼 반복한 문자열을 return
*
* my_string n result
* "hello" 3 "hhheeellllllooo"
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public class programmer_0_61 { static String a1 = "hello"; static int b1 = 3; public String solution(String my_string, int n) { String answer = ""; for(int i = 0; i < my_string.length(); i++){ for(int k = 0; k < n; k++) answer += my_string.substring(i, i+1); } return answer; } public static void main(String args[]){ programmer_0_61 t = new programmer_0_61(); System.out.println("---------------------------------------"); System.out.println("result = " + t.solution(a1,b1)); System.out.println("---------------------------------------"); } } | cs |