본문 바로가기
Java/프로그래머스

문자 반복출력하기

by 비븽 2023. 6. 6.

[프로그래머스] 문자 반복 출력하기 _ Java (tistory.com)

 

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

class Solution { public String solution(String my_string, int n) { String str = ""; String[] arr = my_string.split(""); for(int i=0; i

yeon-ju-k.tistory.com

이 사람 처럼 풀다가

더 편해보이는 코드 발견해서 나도 받아적음

 

class Solution {
    public String solution(String my_string, int n) {
        String str = "";
        String[] arr = my_string.split("");
        for(int i=0; i<my_string.length(); i++){
            str += arr[i].repeat(n);
        }
        return str;
    }
}