/** * @author WanJl * @version 1.0 * @title HomeWork10 * @description 7月15日作业:定义一个整数数组 `{12, 7, 9, 24, 15, 8, 31, 46}`,遍历数组,统计其中奇数和偶数的个数。 * @create 2026/7/16 */ public class HomeWork10 { public static void main(String[] args) { int[] arr={12, 7, 9, 24, 15, 8, 31, 46}; int count=0; //作为奇数个数 //遍历数组 for (int i = 0; i < arr.length; i++) { //如果某个数组元素余2不等于0,就说明是奇数 if (arr[i]%2!=0){ count++; //就累加1 } } System.out.println("奇数个数:"+count+",偶数个数:"+(arr.length-count)); } }