Java Number byteValue() MethodThe byteValue() is a method of Java Number class which automatically converts the given number into a primitive byte type and returns the value of the specified number as a byte. Syntax:Following is the declaration of byteValue() method: Parameter:
Returns:The byteValue() method returns the numeric value represented by this object after conversion to the primitive byte type. Exceptions:NA Compatibility Version:Java 1.1 and above Example 1Test it NowOutput: Number as Byte: 64 Example 2Test it NowOutput: Integer Number as Byte: -64 Float Number as Byte: -77 Double Number as Byte: 76 Example 3Output: Enter the Number Value: ABCDEF Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at myPackage.NumberByteValueExample3.main(NumberByteValueExample3.java:9) Next TopicJava Number Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India