java - Finding average of row of 2D array -



java - Finding average of row of 2D array -

i'm creating method finds average of doubles in row of 2d array. method takes in char describes grade category row. that, need find average of of items in row. how can find row , calculate average?

here's have far:

import java.util.arrays; public class gradebook { private string name; private char[] categorycodes; private string[] categories; private double[] categoryweights; private double[][] gradetable; public gradebook(string namein, char[] categorycodesin, string[] categoriesin, double[] categoryweightsin) { name = namein; categorycodes = categorycodesin; categories = categoriesin; categoryweights = categoryweightsin; gradetable = new double[5][0]; } public double categoryavg (char gradecategory) { double sum = 0.0; double count = 0.0; int index = 0; if (gradecategory == 'a') index = 0; else if (gradecategory == 'q') index = 1; else if (gradecategory == 'p') index = 2; else if (gradecategory == 'e') index = 3; else if (gradecategory == 'f') index = 4; homecoming sum / count; } }

once row selected have simple 1d-array average on row. like:

for(int i=0; < array[index].length; i++){ sum = sum + array[index][i]; count++; }

java arrays

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -