Jump to content

Repeat a string: Difference between revisions

m
Fixed lang tags.
(Added Scala)
m (Fixed lang tags.)
Line 3:
=={{header|Ada}}==
In [[Ada]] multiplication of an universal integer to string gives the desired result. Here is an example of use:
<lang Ada>with Ada.Strings.Fixed; use Ada.Strings.Fixed;
<lang Ada>
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
 
Line 10 ⟶ 9:
begin
Put_Line (5 * "ha");
end String_Multiplication;</lang>
</lang>
Sample output:
<pre>
Line 17 ⟶ 15:
</pre>
=={{header|C}}==
<lang c>#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 35 ⟶ 32:
int main() {
printf("%s\n", string_repeat(5, "ha"));
}</lang Ada>
}
 
</lang>
 
=={{header|C++}}==
Line 60 ⟶ 55:
 
=={{header|Clojure}}==
<lang clojurelisp>(apply str (apply concat (repeat 5 "ha")))</lang>
 
=={{header|E}}==
Line 66 ⟶ 61:
 
=={{header|Forth}}==
<lang forth>: place-n { src len dest n -- }
: place-n { src len dest n -- }
0 dest c!
n 0 ?do src len dest +place loop ;
Line 73 ⟶ 67:
create test 256 allot
s" ha" test 5 place-n
test count type \ hahahahaha</lang>
</lang>
 
=={{header|Fortran}}==
Line 96 ⟶ 89:
 
=={{header|J}}==
<lang j> 5 ((* #) $ ]) 'ha'
hahahahaha</lang>
5 ((* #) $ ]) 'ha'
hahahahaha
</lang>
 
=={{header|Java}}==
Line 129 ⟶ 120:
 
=={{header|Logo}}==
<lang logo>to copies :n :thing [:acc "||]
to copies :n :thing [:acc "||]
if :n = 0 [output :acc]
output (copies :n-1 :thing combine :acc :thing)
end</lang>
</lang>
or using cascade:
<lang logo>show cascade 5 [combine "ha ?] "|| ; hahahahaha</lang>
<lang logo>
show cascade 5 [combine "ha ?] "|| ; hahahahaha
</lang>
 
=={{header|OCaml}}==
Line 184 ⟶ 171:
repeating it more than 0 times results in the concatenation of the string and (n-1) further repeats.
 
<lang pure>> str_repeat 0 s = "";
> str_repeat 0 s = "";
> str_repeat n s = s + (str_repeat (n-1) s) if n>0;
> str_repeat 5 "ha";
"hahahahaha"
></lang>
>
</lang>
 
=={{header|Python}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.