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);
}
}
要是不转换就是连接了
阅读
上一篇:请教此程序错在哪里?如何改 下一篇:返回列表