Reversing a String can be done in multiple ways, using functions, loops. Let us compare how it is done in Java, JavaScript and Python.
Input: Hello, How are You?
Output: ?uoY era woH ,olleH
Java
public class ReverseString { public static void main(String[] args) { System.out.println(new StringBuilder("Hello, How are You?").reverse().toString()); } }
JavaScript
function reverseString(str) { return str.split("").reverse().join(""); } reverseString("Hello, How are You?");
Python
> 'Hello, How are You?'[::-1]