Online Java Compiler By
JavaTpoint.com
public class JavaCharacterCompareToExample3 { public static void main(String[] args) { Character firstVal = new Character('c'); Character secondVal = new Character('a'); Character thirdVal = new Character('c'); // compare the first character to the second character. intcompare1=firstVal.compareTo(secondVal); // compare the first character to the third character. intcompare2 = firstVal.compareTo(thirdVal); if (compare1 == 0) { System.out.println("The first and second values are equal"); } else if (compare1>0) { System.out.println("The first value is greater than the second value"); } else{ System.out.println("The first value is less than the second value"); } if (compare2== 0) { System.out.println("The first and third values are equal"); } else if (compare2 >0) { System.out.println("The first value is greater than the third value"); } else { System.out.println("The first value is less than the third value"); } } }
Output