Hi, Someone please guide me to get the right sintax to print the numbers of above and below arrays. Right now it print the totals quantity, but what I really want is print each number for above an below array.
Thanks.

public class RandomArray {

    public static void main(String[] args) {
        int num[] = {56,12,78,95,23,67,12,66,11,10,34,56,78,45,76,90,100,2,6,87};
        int l = num.length;
        int i;
        double result = 0.0;

        System.out.println("Array is....");
        for (i = 0; i < l; i++ ){
            if (num[i] > result);
        System.out.print("  " + num[i]);
        result = result + num[i];
        }

        System.out.println("\n");
        System.out.println("The average is  " + result / l + "\n");

        // NUMBERS above AVERAGE
        int greaterThan = 0;    
        for (int j = 0; j < l; j++ ){ 
            if (num[j] >  result / l ){  
                greaterThan ++ ;
        }
        }
        System.out.println("Numbers above the average are... " + "\n");
        System.out.println("  " + greaterThan + "\n");

        //NUMBER below AVERAGE
        int lessThan = 0;    
        for (int j = 0; j < l; j++ ){ 
            if (num[j] <  result / l ){  
                lessThan ++ ;
        }
        }
        System.out.println("Numbers below the average are... " + "\n");
        System.out.print("  " + lessThan);
    }
}

use printlines inside your for loops.
right now you are adding all the values you want to print to a "totalSum" (although you 've called them lessThan and greaterThan).

for instance: replace the line

lessThan ++ ;

by

System.out.println("" + num[j]);

you don't need those lessThan and greaterThan variables, you can remove those from your code.

Stultuske,

Thank you it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.