概要
軟件的基本流程圖是我們在學習編程時的必修課,它很簡單,卻很實用。需要說明的是,UML並不包括軟件的基本流程圖,但是為了方便我自己查閱,所以將基本軟件流程圖歸納到UML系列當中。讀者切不要認為基本流程圖是屬於UML的。本章對介紹的內容包括:
流程圖介紹
流程圖示例
轉載請注明出處:http://www.cnblogs.com/skywang12345/p/3520840.html
流程圖介紹
流程圖(FlowChart)是描述我們進行某一項活動所遵循順序的一種圖示方法。它能通過圖形符號形象的表示解決問題的步驟和程序。好的流程圖,不僅能對我們的程序設計起到作用;在幫助理解時,往往能起到"一張圖勝過千言萬語"的效果。
下面是美國國家標准學會(American National Standards Institute,ANSI)制定的一些常用流程圖符號的表格:
流程圖示例
下面通過一個示例進行演示。
示例代碼
1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3 import java.io.IOException; 4 5 public class MathDemo { 6 7 public static void main(String[] args) { 8 9 System.out.print("please insert a number:"); 10 11 // 計算"0"到"iLen"的合 12 int sum = 0; 13 int iLen = getLen(); 14 for (int i=0; i<iLen; i++) { 15 sum += i; 16 } 17 System.out.println("summary(0~"+iLen+")="+sum); 18 } 19 20 // 讀取一個長度,默認返回100 21 private static int getLen() { 22 try { 23 BufferedReader in = 24 new BufferedReader(new InputStreamReader(System.in)); 25 26 // 讀取一行,字符串 27 String str = in.readLine(); 28 // 將該字符串轉換為int整型數 29 int len = Integer.parseInt(str); 30 31 in.close(); 32 return len; 33 } catch(IOException e) { 34 e.printStackTrace(); 35 return 100; 36 } 37 } 38 }
運行結果:
please insert a number:10 summary(0~10)=45
結果說明:
MathDemo的作用是,讓用戶輸入一個整數。然后計算0到"這個整數"之間的和。
在例子中,輸入的值是10;運行結果是0+1+2+3+4+5+6+7+8+9=45。
示例對應的流程圖
更多內容


