Java Printing Question : Multiple characters through mathematical operations?
Author |
Message |
fastftw
|
Posted: Sat Nov 03, 2012 11:14 am Post subject: Java Printing Question : Multiple characters through mathematical operations? |
|
|
I was looking at some python code and you can print characters multiple times through multiplication in a print statement. Example:
out.write("*"*d)
I was wondering if there is an equivalent in java? Something that would imitate
System.out.println("*"*3);
which would output:
***
Thanks a bunch! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sat Nov 03, 2012 6:02 pm Post subject: RE:Java Printing Question : Multiple characters through mathematical operations? |
|
|
Not as far as I know. Just use a for loop. There might be a string operation that does this (which is independent from the output stream) but I doubt it. |
|
|
|
|
|
DemonWasp
|
Posted: Sun Nov 04, 2012 2:50 pm Post subject: RE:Java Printing Question : Multiple characters through mathematical operations? |
|
|
There's no standard multiplication operation for Strings. The only overloaded operator in Java is string+string, which works for concatenation.
You could write your own, but it wouldn't be as concise, which is fairly common in Java. |
|
|
|
|
|
|
|