본문 바로가기

프로그래밍 문제/정올

126 : 반복제어문1 - 형성평가2

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = -1;
        int count_even = 0, count_odd = 0;
 
        while (true){
            num = sc.nextInt();
 
            if (num == 0)
                break;
 
            if ((num%2== 0)
                count_even++;
            else
                count_odd++;
        }
 
        System.out.println("odd : " + count_odd);
        System.out.println("even : " + count_even);
    }
}
cs