title: Computing the average of an array
body: <p>This is a code to take user imputed grades, find their average, the deviation, and display this information in a table style. My program takes user input and displays the information well, but it won't compute the average and the deviation properly.  When run, it says the average is 0.  I'm doing it the same why my teacher taught us, but I can't find my error.   </p>
  
  <pre><code>import java.util.Scanner;
  
  public class ClassScores{
  public static void main(String[] args){
  String[] names = {"Bashful","Doc","Dopey","Grumpy","Happy","Sleepy","Sneezy"};
  double[] grades = new double[7];
  double mean=0;
  double[] difference = new double[7];
  
  getScores(grades);
  average(grades, mean);
  deviation(grades,mean,difference);
  displayResults(names, grades, difference, mean);
  } 
  
  
  
  public static double[] getScores(double[] grades)
  {
  Scanner kb= new Scanner(System.in);
  System.out.println("Enter grades for students in alphabetical order.");
  for (int i=0;i&lt;grades.length; i++)
  {
      grades[i]=kb.nextDouble();
  }
  return grades;  
  }
  
  public static double average(double[] grades, double mean)
  {
  double total = 0;
  for (double i : grades)
  {
      total += i;
  }
  if (grades.length&gt;0)
  {
      mean = total/grades.length;
  }
  return mean;
  }
  
  public static double[] deviation(double[] grades, double mean, double[] difference)
  {
  for (int i=0; i&lt;grades.length; i++)
  {
      difference[i]=grades[i]-mean;
  }
  return difference;
  }
  
  public static void displayResults(String[] names, double[] grades, double[] difference, double mean)
  {
  System.out.println("The average score is" +mean);
  System.out.println("Student Name   Grade    Mean Deviation");
  
  for (int i=0; i&lt;names.length; i++)
  {
      System.out.printf(names[i]);
      System.out.printf("%20f", grades[i]);
      System.out.printf("%20f", difference[i]);
      System.out.println();
  }
  
  }   
  
  }
  </code></pre>
  
  <p>Here is the edited code for anyone who's curious.</p>
  
  <p>import java.util.Scanner;</p>
  
  <pre><code>public class ClassScores{
  public static void main(String[] args){
  String[] names = {"Bashful","Doc","Dopey","Grumpy","Happy","Sleepy","Sneezy"};
  double[] grades = new double[7];
  double mean=0;
  double[] difference = new double[7];
  
  getScores(grades);
  mean = average(grades);
  deviation(grades,mean,difference);
  displayResults(names, grades, difference, mean);
  }
  
  
  
  public static double[] getScores(double[] grades)
  {
  Scanner kb= new Scanner(System.in);
  System.out.println("Enter grades for students in alphabetical order.");
  for (int i=0;i&lt;grades.length; i++)
  {
      grades[i]=kb.nextDouble();
  }
  return grades;  
  }
  
  public static double average(double[] grades)
  {
  double total = 0;
  for (double i : grades)
  {
      total += i;
  }
  return total/(grades.length);
  }
  
  public static double[] deviation(double[] grades, double mean, double[] difference)
  {
  for (int i=0; i&lt;grades.length; i++)
  {
      difference[i]=grades[i]-mean;
  }
  return difference;
  }
  
  public static void displayResults(String[] names, double[] grades, double[] difference, double mean)
  {
  System.out.println("The average score is" +mean);
  System.out.println("Student Name   Grade    Mean Deviation");
  
  for (int i=0; i&lt;names.length; i++)
  {
      System.out.printf(names[i]);
      System.out.printf("%20f", grades[i]);
      System.out.printf("%20f", difference[i]);
      System.out.println();
  }
  
  }   
  
  }
  </code></pre>