हिंदी

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

Advertisements
Advertisements

प्रश्न

Fill an array (type int, size 10).

Print its even elements.

कोड लेखन
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 11: Programs Overall - Arrays [पृष्ठ २५२]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
Arrays | Q 1. | पृष्ठ २५२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×