日期:2014-05-20  浏览次数:21094 次

String 类型的可以和int 的相加?
public   class   A   {
  public   static   void   main(String[]   args)   {
  String   str   = "420 ";
  str   +=   42;
  System.out.print(str);
  }
  }

------解决方案--------------------
42转成字符串,加在420后边
------解决方案--------------------
是字符串连接,不是数值相加
------解决方案--------------------
想要数值相加就要转换
如下:
public class A {
public static void main(String[] args) {
String str = "420 ";
int a=Integer.parseInt(str);
a +=42;
System.out.print(a);
}
}
要是不转换就是连接了