Code Snippet: Print String Backwards

From Coder Merlin

Print String Backwards[edit]

Swift[edit]

let string = "That Which Survives"
for character in string.reversed() {
    print(character)
}

Python[edit]

string = "That Which Survives"
# Short & Fast
print(string[::-1])
# More readable
print(''.join(reversed(string)))

Source

Java[edit]

String string = "That Which Survives";
StringBuilder stringBuilder = new StringBuilder(string);
stringBuilder.reverse();
System.out.println(stringBuilder.toString());

// In one line
System.out.println(new StringBuilder(string).reverse().toString());


Designed with pride in Silicon Valley, CA, USA