【程式語言】JAVA的第五堂課 |算出二維陣列中 奇數 跟 偶數分別有幾個 (odd/even)
Published:
by .public class inclass
{
public static void main(String[] arg)
{
int[][] num = {{3,4,10,2,18},{3,1,6,7,9},{1,4,10,11,5}};
int odd = 0 , even = 0;
for (int i = 0 ; i<3 ; i++) {
for (int j = 0 ; j<5 ; j++) {
if(num[i][j] % 2 == 1) {
odd += 1 ;
}
else {
even +=1;
}
}
}
System.out.println("odd=" + odd +",even=" + even);
}
}