greater than or equalcount in array
Thu Jan 18 2024 18:20:12 GMT+0000 (Coordinated Universal Time)
Saved by
@login
import java.util.Scanner;
public class GreaterThanOrEqualCount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int size = sc.nextInt();
int[] numbers = new int[size];
System.out.println("Enter the elements of the array:");
for (int i = 0; i < size; i++) {
numbers[i] = sc.nextInt();
}
System.out.println("Enter the number to compare:");
int compare = sc.nextInt();
int count = 0;
for (int number : numbers) {
if (number >= compare) {
count++;
}
}
System.out.println("Number of elements greater than or equal to " + compare + ": " + count);
sc.close();
}
}
content_copyCOPY
Comments