- 함수 str_repeat()
1 Go[ | ]

Go
CPU
-1.0s
MEM
-0M
-1.0s
Copy
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Repeat("hello", 3)) // hellohellohello
}
hellohellohello
2 Java[ | ]

Java
Copy
public class MyClass {
public static String str_repeat(String str, int times) {
return new String(new char[times]).replace("\0", str);
}
public static void main(String args[]) {
System.out.println( str_repeat("hello",3) ); // hellohellohello
}
}
Loading
Java
Copy
public class MyClass {
public static String str_repeat(String str, int times) {
StringBuilder sb = new StringBuilder(str.length() * times);
for (int i = 0; i < times; i++) sb.append(str);
return sb.toString();
}
public static void main(String args[]) {
System.out.println( str_repeat("hello",3) ); // hellohellohello
}
}
Loading
3 JavaScript[ | ]
JavaScript
Copy
var a = "hello";
var b = new Array(3+1).join(a);
console.log( b ); // hellohellohello
▶ | hellohellohello |
JavaScript
Copy
String.prototype.repeat=function(n){return new Array(n+1).join(this)}
console.log( "hello".repeat(3) ); // hellohellohello
▶ | hellohellohello |
4 Perl[ | ]
Perl
Copy
print "hello" x 3 # hellohellohello
Loading
5 PHP[ | ]

PHP
Copy
echo str_repeat("hello", 3); // hellohellohello
Loading
6 Python[ | ]
Python
Copy
print( "hello" * 3 ) # hellohellohello
Loading
7 같이 보기[ | ]
로그인하시면 댓글을 쓸 수 있습니다.