Files
Java/Experiment/graph/Exp2/PrimeNum.mermaid
2025-11-06 10:29:13 +08:00

26 lines
795 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
flowchart TD
A[开始] --> B[定义 start = 100, end = 2000]
B --> C[初始化 num_in_line = 0]
C --> D["输出 100~2000之间的素数有"]
D --> E[循环: i = start 到 end]
E --> F{"isPrime(i)?"}
F -- 是 --> G[num_in_line++]
G --> H{num_in_line % 5 == 0?}
H -- 是 --> I[输出 i 并换行]
H -- 否 --> J[输出 i 和空格]
I --> K{i < end?}
J --> K
K -- 是 --> E
K -- 否 --> L[结束]
F -- 否 --> K
subgraph isPrime函数
M["isPrime(n)"] --> N{n <= 1?}
N -- 是 --> O[返回 false]
N -- 否 --> P["循环: i = 2 到 sqrt(n)"]
P --> Q{n % i == 0?}
Q -- 是 --> R[返回 false]
Q -- 否 --> S{"i < sqrt(n)?"}
S -- 是 --> P
S -- 否 --> T[返回 true]
end