Java Number shortValue() Method

The shortValue() method of Java Number class returns the value of the specified number as a short type after a primitive conversion.

Syntax:

Following is the declaration of shortValue() method:

Parameter:

DataTypeParameterDescription
NANAThis method does not accept any parameter.

Returns:

The shortValue() method returns the numeric value represented by this object after conversion to type short.

Exceptions:

NA

Compatibility Version:

Java 1.1 and above

Example 1

Test it Now

Output:

Output Value = 8311
Output Value = 28482

Example 2

Test it Now

Output:

-92
53
23454
-7753

Example 3

Output:

Enter the desired Input: -12345ABCD
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.NumberShortValueExample3.main(NumberShortValueExample3.java:9)





Latest Courses