Source of iterativeString.java


  1: public class iterativeString
  2: {
  3:         public static void writeBackward(String s, int size)
  4:         {
  5:                 // Iterative version.
  6:                    while (size > 0)
  7:                    {
  8:                       System.out.print(s.substring(size-1, size));        //changed to just print not println
  9:                       --size;
 10:                    }  // end while
 11:         }  // end writeBackward
 12: 
 13:         public static void main(String[] args)
 14:         {
 15:                         String str = "Hello world!";
 16:                         writeBackward(str, str.length());
 17:                         System.out.println();
 18:         }
 19: 
 20: }