+ 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.

2nd Mar 2020, 12:53 PM
Muhammad Bilal
Muhammad Bilal - avatar
11 Antworten
+ 10
Just use for or while loop to make iterations
2nd Mar 2020, 8:04 PM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
2nd Mar 2020, 8:44 PM
Tashi N
Tashi N - avatar
+ 2
🌟SUJAN KHARAL🌟 Any alternative for that?? I want to write a string n times.
2nd Mar 2020, 1:01 PM
Muhammad Bilal
Muhammad Bilal - avatar
+ 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!
2nd Mar 2020, 1:53 PM
Sujan Kharal
Sujan Kharal - avatar
+ 1
Use a for or a while loop for n iterations. Isn't that the easiest way possible?
2nd Mar 2020, 1:37 PM
Avinesh
Avinesh - avatar
2nd Mar 2020, 1:57 PM
Muhammad Bilal
Muhammad Bilal - avatar
+ 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.
4th Mar 2020, 4:00 AM
Sanchay Kumar
Sanchay Kumar - avatar
+ 1
use repeat(); EX: String hello = "Hello World..!"; System.out.println(hello.repeat(5));
5th Mar 2020, 6:54 AM
ThisaruD
ThisaruD - avatar
0
I think there might be a builtin method in Java to multiply strings, but you can easily define one by yourself.
2nd Mar 2020, 1:01 PM
Seb TheS
Seb TheS - avatar
0
Convert string into int and then multiply.. It may have Exception
3rd Mar 2020, 9:52 AM
Samiun Nafis
Samiun Nafis - avatar
0
no
9th Mar 2020, 12:42 PM
tirumal kumar
tirumal kumar - avatar