java 计算奇数和偶数的个数

源程序:

public class Test{
 public static void main(String args[]){
  int odd , even ;
  odd = 0 ;
  even = 0 ;
  int score[] = null ;
  score = new int[10] ;
  for(int i = 0 ; i < score.length ; i++){
   score[i] = i ;
  }
  for(int i = 0 ; i < score.length ; i++){
   if(score[i] % 2 == 0){
    even++;
   }
   else
    odd++ ;
  }
 System.out.println("odd = " + odd +"  even = " + even);
 }
}

运行结果:

java <wbr>计算奇数和偶数的个数

你可能感兴趣的:(java 计算奇数和偶数的个数)