java.lang.numberformatexception

来源:互联网 发布:excel对比2张表的数据 编辑:程序博客网 时间:2024/04/26 21:16

一段小程序,String转换为基本类型

public class parse//有误的代码{    public static void main(String[] args)    {        String str="ab";        int i=Integer.parseInt(str);        System.out.println(i);    }}

这里写图片描述

解释:该方法是针对数字类的字符串,例如:计算器,在输入框中输入数字,这是字符串类型的,转换为int。

public class parse//正确的代码{    public static void main(String[] args)    {        String str="456";        int i=Integer.parseInt(str);        System.out.println(i);    }}

补充:java类型转换

这里写图片描述

0 0
原创粉丝点击