public class number {
public static void main(String[] args) {
String A=“1,2,3,4,5,6,7,8,9,10”;
String[]S =A.split(","); //然后使用split方法将字符串拆解到字符串数组中
Integer[] B = new Integer[S.length]; //定义一个长度与上述的字符串数组长度相通的整型数组
for(int a=0;a<S.length;a++){
B[a] = Integer.valueOf(S[a]); //然后遍历字符串数组,使用包装类Integer的valueOf方法将字符串转为整型
}
for(int b=0;b<B.length;b++){
System.out.println(B[b]);
int sum=0;
System.out.println("一维数组中各元素的和是:");
for (int i=0;i<10;i++){
if (i==9){
System.out.print(B[i]+"=");
}else{
System.out.print(B[i] + "+");
}
sum=sum+B[i];
}
System.out.println(sum);
}
}}
//参考了高手编程自己写了一篇,不足之处还望指正。