"Hello world" is not really good to demonstrate the functional approach, as there is nothing functional about it. (In fact, as @delnan noted, writing to the standard output is considered a side effect, so this program can never be made purely functional.)
The most likely reason for you to need var
is using imperative style loops, which is indeed not the functional approach. The functional equivalent would be to either use some of the available filter / transform functions on a collection, or use recursion.
Simple example: finding all strings in a list which start with 'F'. Imperative style (Java):
List<String> result = new ArrayList<String>();
for (String s : strings) {
if (s.startsWith("F")
result.add(s);
}
Imperativeness would be even more pronounced with the old style iterator loop.
In contrast, functional style could be something like:
val result = strings.filter(_.startsWith("F"))