Pages

Wednesday, September 16, 2015

Count Even and Odd Numbers (CPROM Uitm Arau 2015)

Input
The number of input must be determine by the user. After that, based on the integer entered by user, determine whether the integer is an odd or even number to count the total number of even and odd number.
The input must be read from standard input.

Output
The output of the program should display the total of odd and even number.
The output must be written to standard output.


Samples Input
6
1
2
3
4
5
6

Output
3
3


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q4{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
            
      int cases = scan.nextInt();
      int counte=0,counto=0;
            
      for(int x=0;x<cases;x++){
         int in = scan.nextInt();
         
         int temp = (in%2 == 0)?counte++:counto++;        
      }
      
      System.out.println(counte);
      System.out.println(counto);
   }
}

No comments:

Post a Comment