Below is a method that, given an integer,
public static int integerK(int n) {
int k = 0;
while ((k + 1)*(k + 1) <= n)
{
k++;
}
return k;
}You can approximate
Below is a method that, given an integer,
public static double piApprox(int j) {
double pi = 1;
for (int i = 1; i < j; i++) {
if (i % 2 != 0) {
pi -= (1/(double)(2*i+1));
} else {
pi += (1/(double)(2*i+1));
}
}
return 4*pi;
}Below is a method,
Where
public static double standardDeviation(double[] s) {
double sumArray = 0.0;
for(int i = 0; i < s.length; i++) {
sumArray += s[i];
}
double average = sumArray/s.length;
double sumStandardDeviation = 0.0;
for(int i = 0; i < s.length; i++) {
sumStandardDeviation += Math.pow(s[i] - average, 2);
}
double standardDeviation = Math.pow((sumStandardDeviation/(s.length)), 0.5);
return standardDeviation;
}Below is a method,
public static int[] reverseArray1(int[] s) {
if (s.length == 2) {
int s1 = s[0];
s[0] = s[1];
s[1] = s1;
}
else if (s.length > 2) {
int s1 = s[0];
s[0] = s[s.length-1];
s[s.length-1] = s1;
int[] z = new int[s.length-2];
System.arraycopy(s, 1, z, 0, s.length-2);
reverseArray1(z);
System.arraycopy(z, 0, s, 1, z.length);
}
return s;
}Below is a variation of method
public static int[] reverseArray2(int[] s0) {
int[] s1 = new int[s0.length];
for(int i = 0; i < s0.length; i++) {
System.arraycopy(s0, s0.length-1-i, s1, i, 1);
}
return s1;
}Below is a method,
public static double[][] addArray(double[][] a, double[][] b) {
double[][] c = new double[a.length][a[0].length];
for (int row = 0; row < a.length; row++) {
for (int col = 0; col < a[row].length; col++) {
c[row][col] = a[row][col] + b[row][col];
}
}
return c;
}