Byte.compare(): This method is available in the java.lang.Byte class of Java.
Syntax:
int java.lang.Byte.compare(byte x, byte y)
This method takes two arguments of type byte as its parameters. This method compares two-byte values numerically.
Parameters: Two parameters are required for this method.
x: the first byte to compare.
y: the second byte 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.
For Example:
Byte.compare(2,3) = > It returns -1.
Approach
Java
public class ByteCompare {public static void main(String[] args) {byte x = 2, y = 3;System.out.println(Byte.compare(x, y));}}
Output:
-1
No comments:
Post a Comment