java.lang.Short.parseShort(String s, int radix)%uA0方法解析字符串参数作为有符号short 在由第二个参数指定的基数。
声明
以下是java.lang.Short.parseShort()方法的声明
public static short parseShort(String s, int radix) throws NumberFormatException
参数
-
s%uA0-- 这是要分析包含short表示的字符串。
-
radix%uA0-- 这是用来在解析s的基数
返回值
此方法返回由指定基数的字符串参数表示的short值。
异常
-
NumberFormatException%uA0--%uA0如果该字符串不包含一个可分析的short。
例子
下面的例子显示java.lang.Short.parseShort()方法的使用。
package com.yiibai import java.lang.* public class ShortDemo { public static void main(String[] args) { String str = "1000" // returns signed decimal short value of string short shortValue = Short.parseShort(str) // prints signed decimalshort value System.out.println("Signed decimal short value for given String is = " + shortValue) // returns the string argument as a signed short in the radix shortValue = Short.parseShort(str,2) System.out.println("Signed decimal short value for specified String with radix 2 is = " + shortValue) // returns the string argument as a signed short in the radix shortValue = Short.parseShort("11",8) System.out.println("Signed decimal short value for specified String with radix 8 is = " + shortValue) } }
让我们来编译和运行上面的程序,这将产生以下结果:
Signed decimal short value for given String is = 1000 Signed decimal short value for specified String with radix 2 is = 8 Signed decimal short value for specified String with radix 8 is = 9