中央論壇 - CENTER BBS

標題: IVE Lab 7-6 Sample [打印本頁]

作者: f66666602    時間: 2007-7-27 21:16
標題: IVE Lab 7-6 Sample
// IVE Lab 7-6

public class Lab_7_6_sum_of_integer__2 {
  
  static int result;
  static int num;
  
  public static void main(String[] args) {
   
    result = 0;
    for(num = 1; num <= 20; num++) {
      
      if(num == 10 || num == 11) {
        continue;
      } else {
        result += num;
      }
    }
    System.out.println("The sum of number 1-20 is " + result + ".\nThe last number have been add is " + num);
  }
}




歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/) Powered by Discuz! X3