Short.compareUnsigned() in Java

Short.compareUnsigned(): This method is available in java.lang.Short class of Java.

Syntax:

int java.lang.Short.compareUnsigned(short x, short y)

This method takes two arguments of type short as its parameters. This method compares two short values numerically treating the values as unsigned.

Parameters: Two parameters are required for this method.

x: the first short to compare.

y: the second short to compare.

Returns:

1. The value 0 if x == y.

2. A value less than 0 if x < y as unsigned values.

3. A value greater than 0 if x > y as unsigned values.

Exceptions: NA

Approach

Java

public class ShortcompareUnsigned {
    public static void main(String[] args) {

        short x = 2, y = 3;
        System.out.println(Short.compareUnsigned(x, y));
    }
}

Output:

-1


No comments:

Post a Comment