Chapter 10 Strings and Characters (Business web hosting) 565 1 //

Chapter 10 Strings and Characters 565 1 // Fig. 10.15: StringBufferAppend.java 2 // This program demonstrates the append 3 // methods of the StringBuffer class. 4 5 // Java extension packages 6 import javax.swing.*; 7 8 public class StringBufferAppend { 9 10 // test StringBuffer append methods 11 public static void main( String args[] ) 12 { 13 Object o = “hello”; 14 String s = “good bye”; 15 char charArray[] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’ }; 16 boolean b = true; 17 char c = ‘Z’; 18 int i = 7; 19 long l = 10000000; 20 float f = 2.5f; 21 double d = 33.333; 22 StringBuffer buffer = new StringBuffer(); 23 24 buffer.append( o ); 25 buffer.append( ” ” ); 26 27 buffer.append( s ); 28 buffer.append( ” ” ); 29 buffer.append( charArray ); 30 buffer.append( ” ” ); 31 buffer.append( charArray, 0, 3 ); 32 buffer.append( ” ” ); 33 buffer.append( b ); 34 buffer.append( ” ” ); 35 buffer.append( c ); 36 buffer.append( ” ” ); 37 buffer.append( i ); 38 buffer.append( ” ” ); 39 buffer.append( l ); 40 buffer.append( ” ” ); 41 buffer.append( f ); 42 buffer.append( ” ” ); 43 buffer.append( d ); 44 45 JOptionPane.showMessageDialog( null, 46 “buffer = ” + buffer.toString(), 47 “Demonstrating StringBuffer append Methods”, 48 JOptionPane.INFORMATION_MESSAGE ); 49 50 System.exit( 0 ); 51 } 52 53 } // end StringBufferAppend Fig. 10.15 StringBufferclass appendmethods (part 1 of 2). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply