Write a program in java to take 20 numbers as input and store in a Single dimensional array then check and display only positive even numbers and also display how many such numbers found.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[20];
for (int i = 0; i < array.length; i++) {
array[i] = in.nextInt();
}
int count = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] > 0 && array[i] % 2 == 0) {
System.out.print(array[i] + " ");
count++;
}
}
System.out.println("\nTotal: " + count);
}
}
Comments
Leave a comment