Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions JavaUtils/nbproject/project.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,119 @@
// Input 1: [1, 4, 8, 2, 5]
// Output: 2.7386127875258
public class StandardDeviationCalculator implements ArrayToDoubleReducer {
}

@Override
public double reduce(byte[] input) {
double sum = 0, standardDeviation = 0;
int length = input.length;

for(double num : input) {
sum += num;
}

double mean = (sum/length);

for(double num: input) {
standardDeviation += Math.pow(num - mean, 2);
}

return Math.sqrt(standardDeviation/length);
}

@Override
public double reduce(short[] input) {
double sum = 0, standardDeviation = 0;
int length = input.length;

for(double num : input) {
sum += num;
}

double mean = (sum/length);

for(double num: input) {
standardDeviation += Math.pow(num - mean, 2);
}

return Math.sqrt(standardDeviation/length);

}

@Override
public double reduce(int[] input) {
double sum = 0, standardDeviation = 0;
int length = input.length;

for(double num : input) {
sum += num;
}

double mean = (sum/length);

for(double num: input) {
standardDeviation += Math.pow(num - mean, 2);
}

return Math.sqrt(standardDeviation/length);

}

@Override
public double reduce(long[] input) {
double sum = 0, standardDeviation = 0;
int length = input.length;

for(double num : input) {
sum += num;
}
double mean = (sum/length);

for(double num: input) {
standardDeviation += Math.pow(num - mean, 2);
}

return Math.sqrt(standardDeviation/length);

}

@Override
public double reduce(float[] input) {
double sum = 0, standardDeviation = 0;
int length = input.length;

for(double num : input) {
sum += num;
}

double mean = (sum/length);

for(double num: input) {
standardDeviation += Math.pow(num - mean, 2);
}

return Math.sqrt(standardDeviation/length);

}

@Override
public double reduce(double[] input) {
double sum = 0, standardDeviation = 0;
int length = input.length;

for(double num : input) {
sum += num;
}

double mean = (sum/length);

for(double num: input) {
standardDeviation += Math.pow(num - mean, 2);
}

return Math.sqrt(standardDeviation/length);

}
}