UKG interview question

Reverse a string using recursion

Interview Answer

Anonymous

Mar 30, 2022

fairly simple assuming we are only ask to print the reverse string and not return the reverse string: public static void reverseString(String str){ if(str.length() == 0) return; if(str.length() == 1) System.out.println(str); else{ System.out.print(str.charAt(str.length() - 1); reverseString(str.substring(0, str.length() - 1); } }

1