๋ฌธ์์ด์ ๋ฐ๋ณตํด์ ์ถ๋ ฅํ๊ธฐ
for๋ฌธ ํ์ฉ
class Solution {
public String solution(String my_string, int k) {
String answer = "";
for(int i=0; i<k; i++){
answer += my_string;
}
return answer;
}
}
.repeat() ํ์ฉ
class Solution {
public String solution(String my_string, int k) {
return my_string.repeat(k);
}
}
- String.repeat() ๋ฉ์๋๋ String๋ฌธ์์ด์ ํ๋ผ๋ฏธํฐ๋ก ์ฃผ์ด์ง ํ์๋งํผ ๋ฐ๋ณตํ๋ ๋ฉ์๋์ด๋ค.
- java11๋ถํฐ ์ฌ์ฉ๊ฐ๋ฅํ๋ค.
- ํ๋ผ๋ฏธํฐ ์์ ์ง์ ์ ์๋ฌ ๋ฐ์
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] Switch Expressions (Java 12์ดํ) (0) | 2023.11.03 |
---|---|
[JAVA] NaN๊ณผ Infinity (0) | 2023.11.02 |
[JAVA] ๋ฌธ์ ๋ฆฌ์คํธ๋ฅผ ๋ฌธ์์ด๋ก ๋ณํํ๊ธฐ (0) | 2023.10.30 |
[JAVA] ๋ฌธ์์ด ์๋ฅด๊ธฐ(substring() ํ์ฉ) (0) | 2023.10.27 |
[JAVA] ๋ฌธ์์ด์ ํ๋์ฉ ๋๋๊ธฐ(toCharArray(), charAt() ํ์ฉ) (0) | 2023.10.26 |