Reverse

Run Settings
LanguageJava
Language Version
Run Command
class Main { public static String reverseIterative(String string){ String reversedString=""; for (int i=0; i < string.length(); i++){ reversedString += string.charAt(string.length()-1-i); } return reversedString; } public static String reverseRecursive(String string){ if (string == null || string.isEmpty()){ System.out.println("Empty string cannot be reversed."); return ""; } return reverseRecursive(string, string.length()-1); } public static String reverseRecursive(String string, int index){ if (index == 0){ return ""+string.charAt(0); } return ""+string.charAt(index)+reverseRecursive(string, index-1); } public static void main(String[] args) { System.out.println("ReverseIterative: "+reverseIterative("unodos")); System.out.println("ReverseRecursive: "+reverseRecursive("unodos")); } }
Editor Settings
Theme
Key bindings
Full width
Lines