자바/++
repeat로 문자열 반복해서 이어붙이기
backend dev
2023. 5. 17. 13:35
https://www.javastring.net/java/string/java-string-repeat-method
Java String repeat() Method
Java String repeat() method returns a new string whose value is the concatenation of this string given number of times.
www.javastring.net
public static void main(String[] args) throws NumberFormatException, IOException {
String a = "hello";
System.out.println(a.repeat(0)); //빈값
System.out.println(a.repeat(0).isEmpty());
System.out.println(a.repeat(1)); //자신
System.out.println(a.repeat(2)); //2개 이어붙인결과
System.out.println(a.repeat(3)); //3개 이어붙인결과
}
repeat()에 들어가는 인자는 반복할 횟수이다.