Can someone tell me how to print out each array and its value?

we are given a random array of 1000 doubles. If a value in the array is above or below 90% the average, we are to print the "flagged" values.

So far, I just have it printing one of the "flagged" values, I cannot seem to get it to print each array of where it was "flagged" and its "flagged" value.

If you could just show me how to print each array and its value, I can probably figure it out from there.

Edited 6 Years Ago by jnthn205: n/a

Why don't you re-use/continue use array object on which you calculated average and been flagged? Are there any restrictions that says you need to through all arrays rise flag when need it and only after that do data output?

I dont understand what your saying. Re-use the array on which i calculated the average? What do you mean by that?

yes, we need to go through every element of the array, and if it has been flagged then we need to print out where in the array it was flagged, and the value of the flagged element

Edited 6 Years Ago by jnthn205: n/a

As you did not write properly your first question I'm confused. Do you have many arrays ("each array") or just single ("random array of 1000 doubles")
either way it is simple as this

double sum = 0.0;
for(int i = 0; i < array.length; i ++){
sum = sum + array[i];
}
double avarage = sum / array.length;
double averageVal = average *0.9;
for(int i = 0; i < array.length; i++){
    if(array[i] != averageVal)
    {
        System.out.println("Position in array "+i+" value "+array[i]);
    }
}

Above code can be encapsulate in a method to which you pass array of double type for processing. If this is not what you looking for then you better explain in more details as your descriptions are weak, or even better drop your code

Edited 6 Years Ago by peter_budo: n/a

As you did not write properly your first question I'm confused. Do you have many arrays ("each array") or just single ("random array of 1000 doubles")
either way it is simple as this

double sum = 0.0;
for(int i = 0; i < array.length; i ++){
sum = sum + array[i];
}
double avarage = sum / array.length;
double averageVal = average *0.9;
for(int i = 0; i < array.length; i++){
    if(array[i] != averageVal)
    {
        System.out.println("Position in array "+i+" value "+array[i]);
    }
}

Above code can be encapsulate in a method to which you pass array of double type for processing. If this is not what you looking for then you better explain in more details as your descriptions are weak, or even better drop your code

Awesome thank you. I get it now!

quick edit. This is what I have:

for (int i = 0; i < account.length; i++) {
            double less = account[i]-averageVal;
            if (account[i] > averageVal || account[i] < less) {
                System.out.println("Flagged Account: " + i + " Balance: " + account[i]);
            }
        }

Is that correctly printing the accounts above and below 90 %?

When it prints out, the majority of the accounts print, but not all of them.

Double less is the value for below 90%. Im saying if the balance is less than that value, or if the balance is 90% greater than the average

Edited 6 Years Ago by jnthn205: n/a

This article has been dead for over six months. Start a new discussion instead.