Code Snippet: Print String Backwards

From Coder Merlin
Jump to navigation Jump to search

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());


CoderMerlin™ proudly recommends:
HintIcon.png

Your purchase via these links helps keep  Coder Merlin™ 's orbuculum ablaze. As an Amazon Associate we earn from qualifying purchases. Thank you for your support!


Designed with pride in Silicon Valley, CA, USA