Okay, I have found 2 short codes that work, but I want to understand how they work. I have googled and check the links such as:
http://www.tutorialspoint.com/java/lang/math_pow.htm http://www.tutorialspoint.com/java/lang/math_sqrt.htm
But the explanation there is not clear. So in other words I wish know/understand what's going on in each line of both codes.
A) The below program fragment computes (given an integer array data) and prints the geometric mean of all the entries in data:
double product = 1;// For example, I understand why it is 1, since if it was 0 then the product would be keep getting 0, since any number *0 is always zero.
for(int i=0; i<data.length; i++)//okay for loop is getting out all the intergers from the data array.
product*=data[i];//This is I am not too sure, I guess each item in array is getting multiplied with each other????
double gmean=Math.pow(product,1.0/data.length); // Yes, I hate this line, because I don't understand it, can someone explain this line please? Please use easy English, I am not as smart as you.
B) This second code fragment computes (given an integer array data) and prints the quadratic mean of all the entries in data:
double sum=0; //Okay the sum should be 0 because at the moment nothing has been summed up.
for(int i=0; i<data.length; i++)// Now getting out all the items in array called data.
sum+= data[i]*data[i];//Now I am not too sure, all the items in the array called data is getting multiplied with each other and then getting added up? I am not too sure, if would be good if someone could explain this with easy English.
double qmean = Math.sqrt(sum/data.length);// I hate this line, because I don't understand it.
System.out.println(qmean);// Displays the final result.
Okay as you can see, I do understand some lines in the code, while there are some lines, I didn't understand, it would be so fantastic if someone could explain the lines, I didn't really understand using easy English and not in a complicated way.
Thanks in advance.