
내가 작성한 코드
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(); // 반복 횟수
String answer = ""; // 출력할 문자열
// 반복 횟수만큼 문자열 연결
for(int i = 0; i < n; i++) {
answer += str;
}
System.out.println(answer);
sc.close();
}
}
다른 사람의 코드
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();
System.out.println(str.repeat(n));
}
}
repeat(정수)
: 정수만큼 반복해서 출력함Share article