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"));
}
}