English

Fill an array (type int, size 10). Print its even elements.

Advertisements
Advertisements

Question

Fill an array (type int, size 10).

Print its even elements.

Code Writing
Advertisements

Solution

import java.util.*;
class clArrays
{
   void main()
   {
      Scanner sc = new Scanner (System.in);
      int R[] = new int [10];
      System.out.println("Enter 10 elements for the array : ");
      for(int j =0; j <= 9; j++)
        {
           System.out.print("Fill cell number " + j +“ : ");
           R[j] = sc.nextInt();
        }
        System.out.println("\f The Array elements are : ");
        for(int j = 0; j <=9; j++)
        {
           System.out.print(" " + R[j]);
        }
        System.out.println("\n\n The Even Array elements are : ");
        for(int j = 0; j <= 9; j++)
        {
           if(R[j]%2=0)
           {
              System.out.print(" " + R[j]);
           }
        }
   }
}

Output:

The array elements are:

65 62 42 45 84 86 71 73 55 52

The Even Array elements are: 

62 42 84 86 52

shaalaa.com
  Is there an error in this question or solution?
Chapter 11: Programs Overall - Arrays [Page 252]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 11 Programs Overall
Arrays | Q 1. | Page 252
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×