How to print character repeatedly using specifier instead of loop in java?

Viewed 45

I want to print a char '=' repeatedly where I give the no. of times the asterisk should be repeated.

Example: count = 20 and I want to print ==================== using printf() and format specifiers.

1 Answers

String#repeat

Simply append a string generated by String#repeat method, in Java 11+.

String result = "=".repeat( 20 ) ;
Related