3:53 pm - Saturday March 24, 2655

Character Example Program for compareTo(Character anotherCharacter)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
//Character Example Program for compareTo(Character anothercharacter)
/**
 * @author:candidjava.com
 * @description:Compares two Character objects numerically using
 * compareTo(character anothercharacter)
 */
public class CompareEx {
	public static void main(String args[]) {
		// create a character
		Character a = new Character('a');
		Character b = new Character('b');
		// compare two strings stored in difference variable
		int difference = a.compareTo(b);
		// compare character numerically
		if (difference == 0) {
			// difference is zero both are equal
			System.out.println("a is equal to b.");
		} else {
			System.out.println("Both Characters are not equal");
		}
	}
}

OUTPUT:
Both Characters are not equal

Filed in: Z-A All Java Codes

Comments are closed.