ForEx03.java-for문

CODEDRAGON Development/Java

반응형

1부터 100까지의 누적 합 구하기

   

   

소스코드

   

  1. public class ForEx03 {
  2.    
  3.         public static void main(String[] args) {
  4.                  
  5.                 int total = 0;
  6.                 for(int i=1; i<=100; i++){
  7.                         total += i;
  8.                         System.out.println("1부터 " + i + " 까지의 합은 " + total + " 입니다");
  9.                 }
  10.         }
  11. }


   

출력결과

   

   

   

반응형