當前位置:生活全書館 >

IT科技

> repeat java

repeat java

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java repeat是什麼?讓我們一起來了解一下吧!

Javarepeat是通過使用簡單的Java程式,學習重複給定字串N次,以創造含有所有重複的新字串。使用方法sting.repeat(N)和使用常規方法該表示式可在java10中使用。

 

java repeat
   

String.repeat():返回一個字串,該字串的值是給定字串的重複 count 次的串聯。如果字串為空或 count 為零,則返回空字串。

/*** Parameters:* count - number of times to repeat** Returns:* A string composed of this string repeated count times or the empty string if this string is empty or count is zero** Throws:* IllegalArgumentException - if the count is negative.*/

實戰演練,具體步驟如下:

str = "IncludeHelp"//"IncludeHelp"str.repeat(3)//"IncludeHelpIncludeHelpIncludeHelp"str.repeat(0)//""str.repeat(str.length)//"IncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelp"str.repeat(-1)/*VM424:1 Uncaught RangeError: Invalid count value    at String.repeat ()    at :1:5*/

標籤: java repeat
  • 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/33e50m.html