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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
