import java.util.Scanner;
import java.util.ArrayList;
public class MyClass {
public static void printGPA(Scanner scan){
System.out.println("How many courses are you taking?");
int numCourses = scan.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
int i = 1;
while (i <= numCourses){
System.out.println("What's your GPA in course "+i);
int element = scan.nextInt();
list.add(element);
i++;
}
double avg = 0;
for (int w : list){
avg += w;
}
System.out.println("Your average GPA for all your courses is " + (avg / numCourses));
}
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
printGPA(scan);
}
}
I hope this helps!