본문 바로가기
알고리즘/백준

[백준 2675번 ː 자바(JAVA)] 문자열 반복

by 그릿er 2020. 7. 14.

 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

import java.util.*;

 

public class Baekjoon2675 {

 

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        

        for(int i=0; i<n; i++) {

            int re = sc.nextInt();

            String s = sc.nextLine().trim();

            

            for(int k=0; k<s.length(); k++) {

                for(int j=0; j<re; j++) {

                    System.out.print(s.charAt(k));

                }

            }

            System.out.println();

        }

        

        

        sc.close();

 

    }

 

}

 

 

 

 

 


※ error solve

nextLine은 공백까지 읽는다. 이에 따라 공백도 숫자대로 반복되어서 '출력 형식이 잘못되었습니다'라는 메시지가 반복되어서 trim()으로 공백을 없애주었다.