Integer 类在对象中包装了一个基本类型 int 的值。Integer 类型的对象包含一个 int 类型的字段。此外,该类提供了多个方法,能在 int 类型和 String 类型之间互相转换,还提供了处理 int 类型时非常有用的其他一些常量和方法。
public class Summation {
public static void main(String[] args) {
String str[] = {"89","12","10","18","35"};
int sum = 0;
for (int i = 0 ; i < str.length ; i++){ //遍历每一个数组元素
int myint = Integer.parseInt(str[i]); //将str[]数组中的每一个元素转换为int型
sum = sum + myint;
}
System.out.println("数组中的各个元素之和:" + sum);
}
}