Your code works almost fine, except for the last step in the average calculation. The problem is that if you divide an integral number (sum) with another integral number (number of students in a given section) the result will be an integral number, i.e., the fractions are ignored.
To have the fractions included, you need to use a floating-point number, such as double.
To fix this, the easiest solution is to turn sum into a double instead of int.
You don't need to update sum's value to be the average (/=) so you can just use simple division (/) instead of assignemnt with division (/=). It does not cause any actual problem, the result would be the same. It's just pointless to change sum in the final step so why do it? :)
Last, but not least, the class having the main() function should be called Main.
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of sections: ");
//inputting the number into numSec
int numSec = input.nextInt();
//inputting the number of students per section
//creating an Array called numStu to create a series of containers to store the number of students
int[] numStu = new int[numSec];
for (int i = 0; i < numSec; i++){
System.out.print("Enter the number of students in section " + (i+1) + " : ");
numStu[i] = input.nextInt();
}
// new 2d Array to put the exam scores of students per section
int[][] scores = new int[numSec][];
for (int sectionIndex = 0; sectionIndex < numSec; sectionIndex++){
scores[sectionIndex] = new int[numStu[sectionIndex]];
for (int studentIndex = 0; studentIndex < numStu[sectionIndex]; studentIndex++){
System.out.print("Enter the exam score of student " + (studentIndex+1) + " of section " + (sectionIndex+1) + " : ");
scores[sectionIndex][studentIndex] = input.nextInt();
}
}
double[] average = new double[numSec];
for (int sectionIndex = 0; sectionIndex < numSec; sectionIndex++)
{
//System.out.print("Section " + (sectionIndex + 1) + ": ");
double sum = 0.0;
for (int studentIndex = 0; studentIndex < numStu[sectionIndex]; studentIndex++)
{
//System.out.print(scores[sectionIndex][studentIndex] + ", ");
sum += scores[sectionIndex][studentIndex];
}
//System.out.println();
average[sectionIndex] = sum / numStu[sectionIndex];
System.out.println("The average score in section " + (sectionIndex+1) + " : " + average[sectionIndex]);
}
}
}
Note
The original description (see here) has incorrect results. Feel free to check things with a calculator. For the inputs provided in that example input the correct averages are:
85.33
89.0
86.4