class CharExample {
	public static void main(String [] args){
		String s="ABCDEFG";
		char c; // Hold a single character
		c='Z';
		System.out.println("So c holds the character "+c);

		// Gets the single character at position 3 in string s.
		c=s.charAt(3);

		System.out.println("The character at position 3 "+
			"in the string refered to by s is "+c);
		System.out.println("So c now holds the character "+c);

		// Characters and comparison operators
		boolean b;
		b=(c=='C');
		System.out.println("the stmt (c is the character 'C') is "+b);
		b=(c=='D');
		System.out.println("the stmt (c is the character 'D') is "+b);

		/* Characters can be interpreted as integers and vice versa*/

		int i;
		i=c; // Java allows you to convert characters to integers
		System.out.println("c has character "+c+
			" which corresponds to integer "+i);
		i=i+7;
		char c7; // To convert back, you have to cast
		c7=(char)i;
		System.out.println("Now i="+i+
			" which corresponds to the character "+c7);

		/* Characters and arithmetic. Java makes it convenient for you
		to find the 'next' character or to compare characters.
		The ordering of characters is 'a'-'z', 'A'-'Z', '0'-'9' 
		the blank character ' ' comes before all other 
		printable characters */

		// This following first converts the character c to an integer, 
		// then adds 1 to the integer, 
		// then reinterprets the result as a character
		c=(char)(c+1); 
		System.out.println("So c now holds the character "+c);
		c=(char)(c+1);
		System.out.println("So c now holds the character "+c);
		c=(char)(c+1);
		System.out.println("So c now holds the character "+c);

		/* Characters and comparisons */

		b=('K'>c); 
		System.out.println("the statement ('K'>c) is "+b);

		b=('A'>c); 
		System.out.println("the statement ('A'>c) is "+b);

		char c2;
		c2='D';
		b=(c==c2);
		System.out.println("the statement (c == c2) is "+b);
	}
}
