English 中文(简体)
计算第2类中平均和标准偏差
原标题:calculate mean and standard deviation per row in array 2 dimensional
  • 时间:2012-01-12 18:37:44
  •  标签:
  • java
  • arrays

I have 2 dimensional array, I need too calculate mean and standard deviation per row and store it in the proper place. I have write the code but it still give me the wrong result, not giving the correct answer of the intended value. could anyone help me, perhaps my code is just wrong but i dont know how to correct it. Here s the array

enter image description here

And here s the code itself:

public void analyze(String[][] arr) {
   double res = 0.0;
   double avg = 0;
   double variance = 0;
   double SD;
   double Q = 0;
   int index = 0;

   for (int i = 1; i < (arr.length); i++) {
      for (int j = 1; j < (arr[i].length); j++) {
         res = res + Integer.parseInt(arr[i][j]);
      }

      avg = res / (arr[i].length - 1);

      System.out.print("arr[i].length:  " + arr[i].length + "	");
      System.out.println("Average is " + avg);
      /*
      double v = Q + (arr.length - avg) * (arr.length - avg);
      variance = Q / (arr.length - 1);
      SD = Math.sqrt(variance);
      System.out.println("average is " + avg);
      System.out.println("SD");

      double nums[] = { 1.0, 2.3, 3.4, 4.5, 40.5 };
      double result = 0.0;
      for (i = 0; i < nums.length; i++) {
         result = result + nums[i];
      }
      System.out.println("Average is =" + result / nums.length);
      */
   }   
}
问题回答

页: 1 位于 Java的阿雷拉指数为零。 这使你完全错过第一行,下行各翻一栏。

Change

    for(int i=1; i<(arr.length);i++){
        for(int j=1;j<(arr[i].length);j++){
        res = res+Integer.parseInt(arr[i][j]);
    }

to

    for(int i=0; i<(arr.length);i++){
        for(int j=0;j<(arr[i].length);j++){
        res = res+Integer.parseInt(arr[i][j]);
    }

页: 1 Q 。 你们需要重新确定您的外 lo的每 it之间的计算变量。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签