將課程作業01的設計思想、程序流程圖、源程序代碼和結果截圖整理成一篇博文
阿新 • • 發佈:2017-10-07
package static 技術分享 整理 public out 計算 mage 數字
1.程序設計思想
先讓用戶輸入要計算的數字的個數,然後讓用戶輸入這幾個數,將字符型轉化為整數,然後求和,最後輸出所求得的和即可。
2.程序流程圖
3.源程序代碼
package demo;
import java.util.Scanner;
public class argument {
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n;
System.out.println("請輸入要計算的數字個數:");
n=scan.nextInt(); // 求和的數字的個數
int[]Array;
Array=new int [n]; //定義n個整型參數
System.out.println("請輸入"+n+"個數字");
for(int i=0;i<Array.length;i++)
{
Array[i]=scan.nextInt(); //輸入n個數
}//將字符串化為整數
int num=0;
for(int i=0;i<Array.length;i++)
{
num+=Array[i];
}//求和
System.out.println("和為:"+num); //求和結果輸出
}
}
4.結果截圖
將課程作業01的設計思想、程序流程圖、源程序代碼和結果截圖整理成一篇博文