標題: IVE Lab 7-5 Sample [打印本頁] 作者: f66666602 時間: 2007-7-27 21:16 標題: IVE Lab 7-5 Sample 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);
}
}
歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/)