您的位置:首页 > 其它

写一个函数,检查字符是否是整数,如果是,返回其整数值

2011-11-04 12:53 441 查看
public class Converter
{
public static Object convert(String s)
{
try
{
return Integer.valueOf(s);
} catch (Exception e)
{
return new Boolean(false);
}
}

public static void main(String[] args)
{
String s = "12334";
Object o = convert(s);
if (o instanceof Integer)
{
System.out.println(s
+ "     is     an     int     ,it's     value:"
+ ((Integer) o).intValue());
} else
{
System.out.println(s + "is     not     an     int.     ");
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐