Printing reverse of any String without using any predefined function?

Solution 1:

This is the simplest solution:

System.out.print("egaugnal detatneiro tcejbo si avaj");

Solution 2:

You can do it either recursively or iteratively (looping).

Iteratively:

 static String reverseMe(String s) {
   StringBuilder sb = new StringBuilder();
   for(int i = s.length() - 1; i >= 0; --i)
     sb.append(s.charAt(i));
   return sb.toString();
 }

Recursively:

 static String reverseMe(String s) {
   if(s.length() == 0)
     return "";
   return s.charAt(s.length() - 1) + reverseMe(s.substring(0,s.length()-1));
 }