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(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter