命令行参数求和(课程作业01)

  1. 程序设计思想:使用for循环次将args内各个元素转为int型累加。
  2. 程序流程图:
      
  3. 源程序代码:
  4. 1 public class GetSum {
    2     public static void main(String[] args) {
    3         int S = 0;
    4         for(String i:args)
    5             S += Integer.parseInt(i);
    6         System.out.print("Sum = " + S);
    7     }
    8 }
  1. 执行结果:
  2. 关键点:

      调用Integer静态方法parseInt(String)将字符串解析为int。

posted @ 2017-10-06 00:28  ╄冷丶夜♂  阅读(166)  评论(0编辑  收藏  举报