Resolved Program without errors.After running your program
You can check studentGPavg.out
import java.util.*;
import java.io.*;
public class university
{
public static void main(String[] args)throws FileNotFoundException
{
double GPA ;
double sum = 0;
String gender ;
float counter=0;
Scanner inFile = new Scanner(new FileReader("studentGPA.txt"));
PrintWriter outFile = new PrintWriter("studentGPAavg.out");
outFile.println("Code: M F");
outFile.println("Students GPA is:" );
while(inFile.hasNext()){
gender=inFile.next();
if(gender.equalsIgnoreCase("M")){
GPA = inFile.nextDouble();
outFile.printf(" %5.2f", GPA);
sum = sum + GPA;
counter++;
}else if(gender.equalsIgnoreCase("F")){
GPA = inFile.nextDouble();
outFile.printf(" %5.2f", GPA);
sum = sum + GPA;
counter++;
}
}
outFile.println();
outFile.printf("The average of the GPA is: %5.2f %n ", sum/counter);
inFile.close();
outFile.close();
}
}
Click on Thanks link. and mark your thread as resolved.