定義一個整數數組,包含元素{2,6,9,12,8},獲取並輸出數組中數組角標和對應的元素都為偶數的元素與個數
public class Test { public static void main(String[] args) { /*定義一個整數數組,包含元素{2,6,9,12,8},獲取並輸出數組中數組角標和對應的元素都為偶數的元素與個數 PS:0是偶數*/ int[] arr = {2,6,9,12,8}; int count = 0; for (int i = 0; i < arr.length; i++) { if(arr[i] % 2 ==0 && i % 2 == 0){ count++; System.out.print(arr[i]+" "); } } System.out.println("\n個數為:"+count); } }