1. 程式人生 > >命令行參數求和(課程作業01)

命令行參數求和(課程作業01)

string ima 命令行 字符串 令行 int 循環 parse 設計

  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。

命令行參數求和(課程作業01)