Java Integer compareUnsigned() Method
The compareUnsigned() is a method of Java Integer class which compares two integer objects numerically treating the values as unsigned. It returns the result of the value 0 if both arguments are equal; a value less than 0, if the first argument is less than the second argument; a value greater than 0 will be returned, if the first argument is less than the second argument. This method is specified by Comparable<Integer> Interface.
Note: This method cannot be compared to two different types of argument so, both the argument and the number should be the same type.
Following is the declaration of compareUnsigned() method:
The compareUnsigned(int x, int y) method will returns the following values:
Java 1.8 and above
Example 1Test it Now
Output: 0 Output: -1 Output: 1 Output: -1
Example 2Test it Now
x is greater than y
Example 3Test it Now
Enter the first value: -45 Enter the second value: 65 First Value is greater than the second value.
Example 4Test it Now
Campare the user inputs (unsigned integer): -44 -44 88 The Results are: 0 1 -1