Dremendo Tag Line

Input 10 numbers in 1d array and print only two digit even numbers from it in Java

One Dimensional Array - Question 1

In this question, we will see how to input 10 numbers in a one dimensional integer array and print only the two digit even numbers from it in Java programming. To know more about one dimensional array click on the one dimensional array lesson.

Q1) Write a program in Java to input 10 numbers in a one dimensional integer array and print only the two digit even numbers from it.

Program

import java.util.Scanner;

public class Q1
{
    public static void main(String args[])
    {
        int a[]=new int[10], i;
        Scanner sc=new Scanner(System.in);

        System.out.println("Enter 10 numbers");
        for(i=0; i<10; i++)
        {
            a[i]=sc.nextInt();
        }

        System.out.println("\nList of 2 digit even numbers");
        for(i=0; i<10; i++)
        {
            if(a[i]%2==0 && a[i]>=10 && a[i]<=99)
            {
                System.out.print(a[i]+" ");
            }
        }
    }
}

Output

Enter 10 numbers
81
23
42
6
94
30
15
63
19
2
List of 2 digit even numbers
42 94 30
video-poster