Online Java Compiler By
JavaTpoint.com
public class JavaCharacterCompareExample3 { public static void main(String[] args) { char firstVal = 'J'; char secondVal ='J'; char thirdVal = 'M'; // compare the first char to the second CHAR int compareOneTwo = Character.compare(firstVal, secondVal); // compare the first char to the third int compareOneThree = Character.compare(firstVal, thirdVal); if (compareOneTwo == 0) { System.out.println("First and second values are equal."); } else if (compareOneTwo> 0) { System.out.println("First value is greater than the second value."); } else { System.out.println("First value is less than the second value."); } if (compareOneThree == 0) { System.out.println("First and third value are equal."); } else if (compareOneTwo> 0) { System.out.println("First value is greater than the third value."); } else { System.out.println("First value is less than the third value."); } } }
Output