Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa Java-Beginners java program based on array

Have Programming Question? Ask it here!

nainshi jain
java program based on array
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners

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.

View Answers

March 14, 2011 at 11:15 AM

import java.util.*;
class ArrayExample8
    public static void main(String[] args) 
        int less=0,more=0;
        Scanner input=new Scanner(;
        System.out.println("Enter array elements: ");
        int array[]=new int[10];
        for(int i=0;i<array.length;i++){
        System.out.print("Enter number: ");
        int num=input.nextInt();
        for(int i=0;i<array.length;i++){
            else if(array[i]>num){
        System.out.println("Number of array elements less than "+num+": "+less);
        System.out.println("Number of array elements more than "+num+": "+more);

Related Tutorials/Questions & Answers: