title: I want to find the Variance and Standard-Deviation using a 2D array. I did the program but the output coming is incorrect
body: <p>I want to find the Variance and Standard-Deviation using a 2D array I did the program but the output comming is incorrect. Please help me what should I do / modify it to get the required output.</p>
  <p>Input</p>
  <p>3 4</p>
  <p>1 0 1 1 1 1 1 1 1 1 1 1</p>
  <p>Solution output</p>
  <p>0.07513148009038192</p>
  <p>0.27410122234383033</p>
  <p>Expected output</p>
  <p>0.0764</p>
  <p>0.2764</p>
  <p>my program:</p>
  <pre><code>import java.util.*;
  import java.text.DecimalFormat;
  
  public class Source {
     public static void main(String[] args) {
         Scanner s = new Scanner(System.in);
         int n = s.nextInt();
         int m = s.nextInt();
         int[][] arr = new int[n][m];
         for (int i = 0; i &lt; n; i++)
             for (int j = 0; j &lt; m; j++)
                 arr[i][j] = s.nextInt();
         varianceAndStandardDeviation(arr, n, m);
     }
  
     // Method for calculating variance
     static void varianceAndStandardDeviation(int arr[][], int n, int m) {
         // Write your code here
         double[][] diff = new double[n][m];
         double avg = 0f;
         double var = 0f;
         double std_dev = 0f;
         for (int i = 0; i &lt; n; i++)
             for (int j = 0; j &lt; m; j++)
             {
                 avg = (avg + arr[i][j]);
                 avg = avg/(n*m);
                 diff[i][j] = (avg - arr[i][j]);
                 var = ((diff[i][j] * diff[i][j])/((n*m)-1));
                 std_dev = Math.pow(var, 0.5);
             }
             System.out.println(var);
             System.out.println(std_dev);
     }
  }
  </code></pre>