二个数据类型转换的问题 str1=str1+cstr1是一个StringJava中+对String做了重载,只要参加运算的一方是String,+就表示字符串拼接第二个问题:要先将String转换成整数,然后可以相加 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 朋友这样弄:import java.io.*;public class Testkk { public static void main(String[] args) { int aa[]=new int[4]; int c=0; DataInputStream in=new DataInputStream(System.in); System.out.println("请输入数字"); try{ int result=0; String str1=""; String str2=""; for(int i=0;i<aa.length;i++) { str1=in.readLine(); aa[i]=Integer.parseInt(str1); result=result+Integer.parseInt(str1); } str2=Integer.toString(result); //和转换成String类型 System.out.println(str2); } catch(Exception e) { System.out.println(e.getMessage()); } }} 还有你说的“怎样对它进行类型包装”这个你指的是什么?是指package吗? 哦,那可能就是这个int abc=Integer.parseInt(str);把str转换成整形 throws 与 try{ }catch{ } 二维数组的赋值问题 求解 mysql中文乱码 Jacob 操作Excel的问题??? 我这个swing 的repaint()为何没有重画,应该怎么改? 关于JfreeChart制作时序图表 怎样在JBX里调用,ireport的报表预览啊? java线程同步的问题。 为什么我一运行java程序,就出现java.lang.NoClassDefFoundError,Exception in thread "main" 请教问题 关于mysql和java 如何给exe文件制定参数。
import java.io.*;
public class Testkk
{
public static void main(String[] args)
{
int aa[]=new int[4];
int c=0;
DataInputStream in=new DataInputStream(System.in);
System.out.println("请输入数字");
try{
int result=0;
String str1="";
String str2="";
for(int i=0;i<aa.length;i++)
{
str1=in.readLine();
aa[i]=Integer.parseInt(str1);
result=result+Integer.parseInt(str1);
}
str2=Integer.toString(result); //和转换成String类型
System.out.println(str2);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
把str转换成整形