Print List of Even Numbers in Java Array

By | July 4, 2019

Task: write a Java Array Program to Print List of Even Numbers in array.

This Java program is written using:

  • Java array – Declare array of 10 integer numbers.
  • for loop – To input numbers in array and accessing these numbers.
  • if statement in Java – To check a number for Even number.
write a Java Array Program to Print List of Even Numbers in array.

write a Java Array Program to Print List of Even Numbers in array.

Source Code for Java Array Program to print even numbers in Array

/*
 * Java Program To Input 10 integer numbers
 in array and print list of only even numbers in array.
 */
package javaevenarray;
import java.util.Scanner;
/**
 * @author www.EasyCodebook.com
 */
public class JavaEvenArray {

 public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a[]=new int[10],i;
        
        for(i=0;i<a.length ;i++)
        {
            System.out.print("Enter number in Array["+i+"]=");
            a[i]=input.nextInt();
        }
        System.out.println("List of Even Numbers in Array is:");
        for(i=0;i<a.length ;i++)
        {
            if(a[i]%2==0)
              System.out.print(a[i]+", ");
        }
    }
    
}

A Sample run of this Java array program with output is as follows:

 Enter number in Array[0]=10
 Enter number in Array[1]=20
 Enter number in Array[2]=30
 Enter number in Array[3]=40
 Enter number in Array[4]=45
 Enter number in Array[5]=55
 Enter number in Array[6]=60
 Enter number in Array[7]=65
 Enter number in Array[8]=70
 Enter number in Array[9]=90
 List of Even Numbers in Array is:
 10, 20, 30, 40, 60, 70, 90,

Loading

One thought on “Print List of Even Numbers in Java Array

  1. Pingback: Java Array Program to Print Odd Numbers in Array » EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *