Short.compare(): This method is available in java.lang.Short class of Java.
Syntax:
int java.lang.Short.compare(short x, short y)
This method takes two arguments of type short as its parameters. This method compares two short values numerically.
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.
3. A value greater than 0 if x > y.
Exceptions: NA
Approach
Java
public class Shortcompare {public static void main(String[] args) {short x = 1, y = 2;System.out.println(Short.compare(x, y));}}
Output:
-1
No comments:
Post a Comment