JAVA---chapter 7.5
- import java.util.Scanner;
- public class Counteven {
- public static void main(String[] args) {
- int iCountEven; // count even number;
- int i = -1;
- Scanner input = new Scanner(System.in);
- int []iBucket = new int [20];
- do
- {
- i++;
- iBucket[i] = input.nextInt();
- System.out.print(iBucket[i]);
- }while (iBucket[i]!=0);
- int j;
- iCountEven = 0;
- for ( j=0 ; j<i ; j++ )
- {
- if ( iBucket[j] % 2 == 0 )
- iCountEven++;
- }
- System.out.println(" Even number have : " + iCountEven );
- System.out.println("Odd number have : " + (i-iCountEven));
- }
- }
Even number: 2, 4, 6
Odd number : 1, 3, 5, 1
留言
張貼留言