- 最後登錄
- 2024-4-9
- 在線時間
- 9252 小時
- 註冊時間
- 2004-5-23
- 閱讀權限
- 200
- 精華
- 14
- UID
- 5
- 帖子
- 15722
- 積分
- 28040 點
- 潛水值
- 400289 米
| 回覆中加入附件並不會使你增加積分,請使用主題方式發佈附件。 - public class Lab_7_5_sum_of_integer {
-
- static int result;
- static int num;
-
- public static void main(String[] args) {
- result = 0;
- for (num = 1; num <= 20; num++) {
-
- if (result >= 100) {
- break;
- } else {
- result += num;
- }
- }
- System.out.println("The sum of the number 1-20 is " + result + ".\nThe last number have be add is " + num);
- }
- }
複製代碼 ... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |