Java Integer parseUnsignedInt() MethodThe parseUnsignedInt() is a method of Java Integer class. There are three different types of parseUnsignedInt() method which can be differentiated depending on its parameter. These are:
1. Java Integer parseUnsignedInt (String s) MethodThis method parses the String argument as an unsigned decimal integer object. The characters in the string must be decimal digits, except that the first character of the string may be an ASCII plus sign '+' sign to indicate a positive value. It returns the unsigned integer value which is represented by the argument in a decimal integer. 2. Java Integer parseUnsignedInt (String s, int radix) MethodThis method parses the String argument as an unsigned decimal integer object in the specified radix by the second argument. The characters in the string must be decimal digits of the specified argument except that the first character may be an ASCII plus sign '+' to indicate a positive value. The resulting integer value is to be returned. 3. Java Integer parseUnsignedInt (CharSequence s, int beginText, int endText, int radix) MethodThis method parses the CharSequence argument as an unsigned decimal integer in the specified radix argument, beginning at the specified beginIndex and extending to endIndex - 1. This method does not take steps to guard against the CharSequence being mutated while parsing. Syntax:Following are the declarations of parseUnsignedInt() method: Parameter:
Returns:
Exceptions:NullPointerException: If s is null. IndexOutOfBoundsException: If beginIndex is negative, or if beginIndex is greater than endIndex or if endIndex is greater than s.length (). NumberFormatException: If the CharSequence does not contain a parsable int in the specified radix, or if radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX. Compatibility Version:Java 1.2 and above:
Java 9:
Example 1Output: Value = 20 Example 2Output: Exception in thread "main" java.lang.NumberFormatException: For input string: "ABCD" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseUnsignedInt(Integer.java:832) at java.base/java.lang.Integer.parseUnsignedInt(Integer.java:928) at myPackage.IntegerParseUnsignedIntExample2.main(IntegerParseUnsignedIntExample2.java:5 Example 3Output: Output Value = 104 Example 4Output: Enter the Integer Inputs: 150 Enter the Radix Value: 16 Output Value = 336 Example 5Output: Output Value = 13 Example 6Output: Enter the Integer Inputs: 550 Enter the Begining Index: 0 Enter the Ending Index: 2 Enter the Radix Value: 8 Output Value = 45 Output 2 with Exception: Enter the Integer Inputs: 550 Enter the Begining Index: 2 Enter the Ending Index: 5 Enter the Radix Value: 8 Exception in thread "main" java.lang.IndexOutOfBoundsException at java.base/java.lang.Integer.parseUnsignedInt(Integer.java:881) at myPackage.IntegerParseUnsignedIntRadixExample6.main(IntegerParseUnsignedIntRadixExample6.java:15) Next TopicJava-integer-remainderunsigned-method |
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