日期:2014-05-18  浏览次数:20792 次

怎么把String强制转换为int呢
看看这样为什么错呢?
怎么改呢?
  int   shuliang=(int   )request.getParameter( "shuliang ");
报错是这样
inconvertible   types
found       :   java.lang.String
required:   int
    int   shuliang=(int   )request.getParameter( "shuliang ");
                                                                                  ^


------解决方案--------------------
Integer.parseInt(s)
可以把字符串转成整型
------解决方案--------------------
int shuliang=Integer.parseInt(request.getParameter( "shuliang ");)

------解决方案--------------------
同意楼上的
------解决方案--------------------
int i = Integer.valueOf(str).intValue();
也可以的,baidu 上面到处都是的
------解决方案--------------------
int shuliang=Integer.parseInt(request.getParameter( "shuliang "));
不好意思呀。那个分号应该在最后了。哈

------解决方案--------------------
int shuliang=Integer.parseInt(request.getParameter( "shuliang ");)你在吗分号都拷进去了
------解决方案--------------------
Integer.parseInt(s)
------解决方案--------------------
顶一个, 楼主真大方, 简单问题这么多分

我也凑个热闹吧...
------解决方案--------------------
int shuliang=Integer.parseInt(request.getParameter( "shuliang "));