Java parseInt() 方法

Java 教程 · 2019-02-08 11:13:19

parseInt() 方法用于将字符串参数作为有符号的十进制整数进行解析。

如果方法有两个参数, 使用第二个参数指定的基数,将字符串参数解析为有符号的整数。

语法

所有 Number 派生类 parseInt 方法格式类似如下:

static int parseInt(String s)

static int parseInt(String s, int radix)

参数

  • s -- 十进制表示的字符串。

  • radix -- 指定的基数。

返回值

  • parseInt(String s): 返回用十进制参数表示的整数值。

  • parseInt(int i): 使用指定基数的字符串参数表示的整数 (基数可以是 10, 2, 8, 或 16 等进制数) 。

实例

public class Test{
    public static void main(String args[]){
        int x =Integer.parseInt("9");
        double c = Double.parseDouble("5");
        int b = Integer.parseInt("444",16);

        System.out.println(x);
        System.out.println(c);
        System.out.println(b);
    }
}

编译以上程序,输出结果为:

9
5.0
1092

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Release It!

Release It!

Michael T. Nygard / Pragmatic Bookshelf / 2007-03-30 / USD 34.95

“Feature complete” is not the same as “production ready.” Whether it’s in Java, .NET, or Ruby on Rails, getting your application ready to ship is only half the battle. Did you design your system to......一起来看看 《Release It!》 这本书的介绍吧!

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具