๊ด€๋ฆฌ ๋ฉ”๋‰ด

bom's happy life

[JAVA] ๋ฌธ์ž์—ด ๋ฐ˜๋ณตํ•ด์„œ ์ถœ๋ ฅํ•˜๊ธฐ ๋ณธ๋ฌธ

Algorithm๐Ÿ’Œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[JAVA] ๋ฌธ์ž์—ด ๋ฐ˜๋ณตํ•ด์„œ ์ถœ๋ ฅํ•˜๊ธฐ

bompeach 2023. 4. 22. 21:34

๋ฌธ์ œ ์„ค๋ช… : 

๋ฌธ์ž์—ด str ๊ณผ ์ •์ˆ˜ n ์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. st ์ด n ๋ฒˆ ๋ฐ˜๋ณต๋œ ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค์–ด ์ถœ๋ ฅํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด์„ธ์š”.

 

์ œํ•œ์‚ฌํ•ญ :

๐Ÿ”Ž 1 ≤ str ์˜ ๊ธธ์ด ≤ 10

๐Ÿ”Ž 1 ≤ n ≤ 5

 

์ž…์ถœ๋ ฅ ์˜ˆ :

์ž…๋ ฅ #1

string 5

์ถœ๋ ฅ #1

stringstringstringstringstring

 

 

๋ฌธ์ œ

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();
    }
}

 

 

์ •๋‹ต

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();
        
        str = str.repeat(n);
        
        System.out.println(str);
    }
}

 

์„ค๋ช… : repeat๋ฉ”์„œ๋“œ๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜๋งŒ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.  str.repeat(n)์€ ๋ฌธ์ž์—ด str์€ n๋ฒˆ ๋ฐ˜๋ณตํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.