572 Strings and Characters Chapter 10 equivalent. The (Cheapest web hosting)

572 Strings and Characters Chapter 10 equivalent. The method returns the converted character if the character has a lowercase equivalent; otherwise, the method returns its original argument. Figure 10.18 demonstrates static Character methods digit and forDigit, which perform conversions between characters and digits in different number systems. Common number systems include decimal (base 10), octal (base 8) , hexadecimal (base 16) and binary (base 2). The base of a number is also known as its radix. For more information on conversions between number systems, see Appendix E. Line 52 uses method forDigitto convert the integer digitinto a character in the number system specified by the integer radix(also known as the base of the number). For example, the integer 13in base 16 (the radix) has the character value ‘d’. Note that the lowercase and uppercase letters are equivalent in number systems. Line 77 uses method digit to convert the character c into an integer in the number system specified by the integer radix(i.e., the base of the number). For example, the character ‘A’in base 16 (the radix) has the integer value 10. 1 // Fig. 10.18: StaticCharMethods2.java 2 // Demonstrates the static character conversion methods 3 // of class Character from the java.lang package. 4 5 // Java core packages 6 import java.awt.*; 7 import java.awt.event.*; 8 9 // Java extension packages 10 import javax.swing.*; 11 12 public class StaticCharMethods2 extends JFrame { 13 private char c; 14 private int digit, radix; 15 private JLabel prompt1, prompt2; 16 private JTextField input, radixField; 17 private JButton toChar, toInt; 18 19 public StaticCharMethods2() 20 { 21 super( “Character Conversion Methods” ); 22 23 // set up GUI and event handling 24 Container container = getContentPane(); 25 container.setLayout( new FlowLayout() ); 26 27 prompt1 = new JLabel( “Enter a digit or character ” ); 28 input = new JTextField( 5 ); 29 container.add( prompt1 ); 30 container.add( input ); 31 32 prompt2 = new JLabel( “Enter a radix ” ); 33 radixField = new JTextField( 5 ); 34 container.add( prompt2 ); 35 container.add( radixField ); Fig. 10.18 Characterclass staticconversion methods (part 1 of 3). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply