No. Variables can be declared in the middle of a program. You should declare them in whatever location makes the program easiest to understand.
However, variables should be declared in statements that precede the statements that use them.
Here (again) is a sample data file for the program,
called student.data
.
3 87 98 95 4 78 82 91 84
Here is a sample run of the program.
C:\temp>java TestGroups File name? student.data Group A average: 93.33333333333333 Group B average: 83.75 C:\temp>