+ 7
Can we multiply a string with a number?[answered]
Just as in python we mutiply a string with num and get new string num times.
11 Answers
+ 10
Just use for or while loop to make iterations
+ 6
Since Java 11
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#repeat(int)
Usage
"hello".repeat(5);
+ 2
đSUJAN KHARALđ
Any alternative for that?? I want to write a string n times.
+ 2
Muhammad Bilal use loop
For example
for(int i = 1; i <= 100; i++)
{
System.out.println("Hello World!");
}
Output will 100 time Hello world!
+ 1
Use a for or a while loop for n iterations.
Isn't that the easiest way possible?
+ 1
Multiplying a string with a number (say n)means repeating the string n number of times in the output.
In java for repeating the output of the string we can only use loops.
I know this is an exasperating thing but python has this awesome feature.
Example:
print('Awesome' * 3)
Output:
AwesomeAwesomeAwesome
Python has farrago of features of previous programming languages and its own features too which makes the programming world more beautiful.
+ 1
use repeat();
EX:
String hello = "Hello World..!";
System.out.println(hello.repeat(5));
0
I think there might be a builtin method in Java to multiply strings, but you can easily define one by yourself.
0
Convert string into int and then multiply.. It may have Exception
0
no