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 by jnthn205: n/a

2
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by jnthn205

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 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 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!

Delete this post

Edited by jnthn205: quick edit

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 by jnthn205: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.