Login
|
Signup
langref.org
-
scala
and
java
add..
all
clojure
cpp
csharp
erlang
fantom
fsharp
go
groovy
haskell
ocaml
perl
php
python
ruby
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Structure
Loops
Perform an action a fixed number of times (FOR)
Display the string
"Hello"
five times like
"HelloHelloHelloHelloHello"
scala
// Using overloaded '*' operator (String-specific)
print("Hello" * 5)
object SolutionXX extends Application {
// Using overloaded '*' operator (String-specific)
print("Hello" * 5)
}
scala
List.range(0, 5) foreach { (_) => print("Hello") }
object Solution448 extends Application {
List.range(0, 5) foreach { (_) => print("Hello") }
}
scala
for (_ <- List.range(0, 5)) print("Hello")
object SolutionXX extends Application {
for (_ <- List.range(0, 5)) print("Hello")
}
scala
// Lazy version
for (_ <- Stream.range(0, 5)) print("Hello")
object SolutionXX extends Application {
// Lazy version
for (_ <- Stream.range(0, 5)) print("Hello")
}
scala
dotimes(5, _ => print("Hello"))
object Solution451 extends Application {
def dotimes(n : Int, f : Unit => Unit) : Unit = { if (n != 0) { f() ; dotimes(n - 1, f) } }
dotimes(5, _ => print("Hello"))
}
scala
(0 until 5) foreach { (_) => print("Hello") }
object SolutionXX extends Application {
(0 until 5) foreach { (_) => print("Hello") }
}
scala
5 times { print("Hello") }
object SolutionXX extends Application {
5 times { print("Hello") }
}
java
for(int i=0;i<5;i++) {
System.out.print("Hello");
}
public class Solution49 {
public static void main(String[] args) {
for(int i=0;i<5;i++) {
System.out.print("Hello");
}
}
}
Submit a new solution for
scala
or
java
There are 29 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)