Answer to Question #282711 in Java | JSP | JSF for Fakir

Question #282711

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.


1
Expert's answer
2021-12-26T09:41:27-0500
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog