This program should reverse the stringclass jack { public static String reverseString(String s, String result,int l) { if(l>=0) { result=result+s.charAt(l); reverseString(s,result,l-1); return result;} else return "error"; } public static void main(String args[]) { String s="Allen downey"; String result=""; int l=s.length(); String backward=reverseString(s,result,l); System.out.println(backward); } }
But The program is not yielding output... I know what you are thinking.... why can't I just use while or for... But I can't... I am supposed to be able to write the program without any iteration...
please help...