- /**
- * Demonstrates how characters can be
used to perform integer math
- *
- * @author TK Rogers
- * @version 10-13-11
- */
- public class CharacterMath {
- public static void
main ( ) {
-
char c1 = 'a', c2 = 'b', c3 = 'c' ;
-
char capitalLetter = 'A', charAnswer ;
-
int intAnswer ;
-
- charAnswer = ( char ) ( c1 + 2 ) ;
- System.out.println ( "\'" +c1 + "\' + 2 = " + charAnswer + "\n" ) ;
charAnswer = ( char ) ( c1 + 2 - ( 'g' - 'G' ) ) ;
System.out.println ( "\'" +c1 + "\' + 2 - ( \'g\' - \'G\' ) = " + charAnswer + "\n" ) ;
intAnswer = c1 / c2 ;
System.out.println ( "c1 / c2 = " + intAnswer + "\n" ) ;
intAnswer = c1 - c2 ;
System.out.println ( "c1 - c2 = " + intAnswer + "\n" ) ;
intAnswer = 'b' - 'B' ;
System.out.println ( "\'b\' - \'B\' = " + intAnswer + "\n" ) ;
intAnswer = 'm' - 'M' ;
System.out.println ( "\'m\' - \'M\' = " + intAnswer + "\n" ) ;
charAnswer = ( char ) ( c2 - ( 'y' - 'Y' ) ) ;
System.out.println ( "\'" +c2 + "\' - ( \'y\' - \'Y\' ) = " + charAnswer + "\n" ) ;
for ( char x = 'a' ; x < 'z' ; x++ ) {
System.out.println ( x + " = " + ( int ) x + "\t\t" + capitalLetter
+ " = " + ( int ) capitalLetter ) ;
capitalLetter++ ;
}
-
- }
}