[algorithm] 문자열 반복해서 출력하기

인철·2024년 2월 27일
0

algorithm

목록 보기
84/91

문자열 str과 정수 n이 주어집니다.
str이 n번 반복된 문자열을 만들어 출력하는 코드를 작성해 보세요.

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = sc.nextInt();
        System.out.println(str.repeat(n));
    }
}
// repeat(n) 메서드를 사용해도 도기ㅗ

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = sc.nextInt();
        
        for(int i = 0; i < n; i++){
            System.out.print(str);
        }
    }
}// 반복문을 사용해도 된다.
profile
같은글이있어도양해부탁드려요(킁킁)

0개의 댓글