
write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called count() belonging to a class counter.within count findout how many numbers are equal to the no. passed how many are greater and how many are less than the no. passed .finally return the result block to main and print it there.

import java.util.*;
class ArrayExample8
{
public static void main(String[] args)
{
int less=0,more=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter array elements: ");
int array[]=new int[10];
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();
}
System.out.print("Enter number: ");
int num=input.nextInt();
for(int i=0;i<array.length;i++){
if(array[i]<num){
less++;
}
else if(array[i]>num){
more++;
}
}
System.out.println("Number of array elements less than "+num+": "+less);
System.out.println("Number of array elements more than "+num+": "+more);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.