第七章第二十一题(整数求和)(Sum of integers)
- *7.21(整数求和)编写程序,从命令行输入不定数目的整数,然后显示他们的和。
*7.21(Sum of integers)Write a program to input an indefinite number of integers from the command line and display their sum. - 参考代码:
package chapter07;
public class Code_21 {
public static void main(String[] args) {
int sum = 0;
for (int i = 0;i < args.length;i++){
sum += Integer.parseInt(args[i]);
}
System.out.println("The sum of these integer is: " + sum);
}
}
- 结果显示: