Online Java Compiler By
JavaTpoint.com
public class Enum_compareToMethodExample1 { enum Grade{ A1,A2; } public static void main(String[] args) { Grade first, second, third; first = Grade.A1; second = Grade.A2; int val = first.compareTo(second); if(val>0){ System.out.println("A1 is greater than A2."); } else if(val<0){ System.out.println("A2 is greater than A1."); } else{ System.out.println("A1 and A2 both are equal ."); } } }
Output