Ask coding questions

← Back to all posts
Need help with a simple Java programming question
mnp (1)

I added a picture of it. I'm mostly unsure about how to count the data in each.

Voters
mnp (1)
Commentshotnewtop
JoshDaBosh (77)

for the second method:
keep the data elements in an array.

split the array into pairs using this SO thread:
https://stackoverflow.com/questions/27857011/how-to-split-a-string-array-into-small-chunk-arrays-in-java

Then iterate through each element of the array (each one should be a sub-array) and if the average is either less that 68% of the general average of all the elements or greater than 168% of the general average, then store that in a new array and that will be the outliers list.

JoshDaBosh (77)

for the first method: you could get the average of the data elements by summing them and dividing by the amount of objects in the set. then find the outlier numbers by iterating through the data elements and seeing if they are either less than 68% of the average or greater than 168% of the average.

theangryepicbanana (1316)

Can you show what you have so far?

mnp (1)

@theangryepicbanana I don't really have anything. I cant figure out how to start it. I'm confused about how to declare the numbers I want to use

theangryepicbanana (1316)

@mnp I don't know how you do standard deviation in Java, but here's some pseudo-code:
(std = standard deviation)

int[] findOutlier(int[] data) {
    int[data.length] outliers;
    
    for(int i = 0; i < data.length; i++) {
        if(isOutsideAverage(data[i], findStd(data) * 3)) {
            outliers[i] = data[i];
        }
    }
    return outliers;
}

something like that I guess. I haven't used Java in a while, but that hopefully should give you a good idea of what to do.