Java code asks the user to enter the number of grades he want to enter then it enter a function or method to put them into array then enter another method to find average.
the code compile without error but when i run and i put the number of grades but the function grades crash, I am used to code in c++ so i may be missing some basics of java. Your understanding will be appreciated. I hope when fixing it , to tell me what is my mistake.
package lab10ex8;
import java.util.Scanner;
public class Lab10ex8 {
    
    
    public static double[] grades ( int n, double a [] ) {
        Scanner S = new Scanner(System.in);
        double grade=0;
        for(int i=0; i<n ; i++)
        {
            grade = S.nextDouble();
            a[i] = grade;
            
        }
        return a;
    }
    
    public static double average( double a[] ) {
        double average=0;
        double c;
        double sum=0;
        Scanner S = new Scanner(System.in);
        
        for(int i=0; i< a.length ; i++){
            
            c= a[i];
            sum = sum+c;
        }
        average = sum/a.length;
        return average;
    }
    public static void main(String[] args) {
        int n;
        System.out.println( "Enter the number of Grades : " );
        Scanner S = new Scanner(System.in);     
        n=S.nextInt();
        double a[] = null;
        grades(n,a);
        average(a);
        
        
    }
    
}
 
     
     
    