Basic HTML version of Foils prepared Sept 21 1998

Foil 23 Example using StringBuffer

From Java Tutorial 98- 4: Multi-Treading, Useful Java Classes, I/O and Networking NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

A pizza order example.  The bill display uses stringbuffer to line up and display dollar amounts.
This class returns an object of class String that reverses order of characters in its argument:
  • class ReverseString
  • { public static String reverse( String s )
  • { int i, len = s.length();
  • StringBuffer dest = new StringBuffer(len);
  • for( i = (len-1); i >= 0 ; i-- )
  • { dest.append( s.charAt(i) );
  • }
  • return dest.toString();
  • }
  • }



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998