[프로그래머스/JAVA]짝수 홀수 개수

gov's avatar
Dec 02, 2024
[프로그래머스/JAVA]짝수 홀수 개수
Contents
문제풀이

문제

notion image

풀이

class Solution { public int[] solution(int[] num_list) { int[] answer = new int[2]; int even = 0; int odd = 0; // 홀수 for (int i = 0; i < num_list.length; i++) { if (num_list[i] % 2 == 0) { even++; } else { odd++; } } answer[0] = even; answer[1] = odd; return answer; } }
Share article

goho