Java Integer shortValue() MethodThe shortValue() method of Java Integer class returns the value of this Integer as a short type after a primitive conversion. It overrides the shortValue() method of Number Class. Syntax:Following is the declaration of shortValue() method: Parameter:
Returns:The shortValue() method returns the numeric value represented by this object after conversion to type short. Exceptions:NA Compatibility Version:Java 1.0 and above Example 1Test it NowOutput: Value of s = 225 Value of s = -225 Example 2Output: Enter Desired Number: 46546657 short Value is: 16097 Example 3Output: Exception in thread "main" java.lang.Error: Unresolved compilation problems: Type mismatch: cannot convert from double to Integer Type mismatch: cannot convert from String to Integer at myPackage.IntegerShortValueExample2.main(IntegerShortValueExample2.java:6)
Next Topicsignum() Method
|