출처: https://bumcrush.tistory.com/182 [맑음때때로 여름]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
        // 1~100 사이에 있는 숫자 중 짝수들의 합, 홀수들의 합을 구하라.
        
        int sum1=0//짝수합
        int sum2=0//홀수합
        
         for(int i=1 ; 101>i; i++) {
             if(i%2==0) {
                 sum1=sum1+i;
             }
             else {
                 sum2=sum2+i;
             }             
         }
         
         System.out.println("짝수합 = " + sum1);
         System.out.println("홀수합 = " + sum2);
cs

+ Recent posts