String的函数public String repeat(int count),可以将当前字符串重复count次串接起来输出。
如果字符串是空的,或者count的值是0,那么返回空字符串。
代码示例1:
package com.thb;public class Test5 {public static void main(String[] args) {String str = "hello".repeat(2);System.out.println(str);}}
运行输出:

代码示例2:输出多个*号
package com.thb;public class Test5 {public static void main(String[] args) {String str = "*".repeat(20);System.out.println(str);}}
运行输出:
