मराठी

Fill an array (type int, size 10). Count how many elements are >= 50.

Advertisements
Advertisements

प्रश्न

Fill an array (type int, size 10).

Count how many elements are >= 50.

कोड लेखन
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 num " + j + ":");
            R[j] = sc.nextInt();
        }        
        int count = 0;
        for(int j = 0; j <= 9; j++)
        {
            if(R[j] >= 50)
            {
                count++;
            }
        }        
        System.out.print(" Number of elements >= 50 : " + count);
    }
}

Output:

Enter 10 elements for the array:
Fill cell num 0 : 66
Fill cell num 1 : 11 
Fill cell num 2 : 45 
Fill cell num 3 : 54 
Fill cell num 4 : 87 
Fill cell num 5 : 89 
Fill cell num 6 : 23
Fill cell num 7: 32
Fill cell num 8 : 58
Fill cell num 9 : 25 
Number of elements >= 50 : 5

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 11: Programs Overall - Arrays [पृष्ठ २५२]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×