The compare()  method of Integer class compares the two specified int values.

 Syntax

public static int compare(int x, int y)

 Parameters

The parameters ‘x’ and ‘y’ represent the first and second int values to be compared.

 Return Value

This method returns an integer value.

  • It returns zero, if both the parameters are equal(x==y).
  • It returns positive one, if x is greater than y(x>y).
  • It returns negative one, if x if smaller than y(x<y).

Example 1

Output

Example 2

Output

Example 3

Output

Pin It on Pinterest

Share This