File tree Expand file tree Collapse file tree 1 file changed +29
-22
lines changed
Expand file tree Collapse file tree 1 file changed +29
-22
lines changed Original file line number Diff line number Diff line change 11import java .util .Scanner ;
2+
23public class EvenOddArray {
3- public static void main (String [] args )
4- {
5- int n ;
6- Scanner sc = new Scanner (System .in );
7- System .out .println ("Enter the size of the array: " );
8- n = sc .nextInt ();
9- int []arr = new int [n ];
10- System .out .println ("Enter the array elements: " );
11- for (int i = 0 ; i < n ; i ++)
12- {
13- arr [i ] = sc .nextInt ();
14- }
15- int even = 0 , odd = 0 ;
16- for (int i =0 ; i <n ; i ++){
17- if ((arr [i ] % 2 )== 0 )
18- even += 1 ;
19- else
20- odd += 1 ;
21- }
22- System .out .println ("Number of even elements: " + even );
23- System .out .println ("Number of odd elements: " + odd );
24- }
4+ public static void main (String [] args ) {
5+ Scanner sc = new Scanner (System .in );
6+
7+ System .out .println ("Enter the size of the array: " );
8+ int n = sc .nextInt ();
9+
10+ int [] arr = new int [n ];
11+
12+ System .out .println ("Enter the array elements: " );
13+ for (int i = 0 ; i < n ; i ++) {
14+ arr [i ] = sc .nextInt ();
15+ }
16+
17+ int even = 0 , odd = 0 ;
18+
19+ for (int i = 0 ; i < n ; i ++) {
20+ if (arr [i ] % 2 == 0 ) {
21+ even ++;
22+ } else {
23+ odd ++;
24+ }
25+ }
26+
27+ System .out .println ("Number of even elements: " + even );
28+ System .out .println ("Number of odd elements: " + odd );
29+
30+ sc .close ();
31+ }
2532}
You can’t perform that action at this time.
0 commit comments