Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MyClass {
- public static double calculateAverageGrade(double[] grades) {
- double totalGrades = 0;
- for (double grade : grades) {
- totalGrades += grade;
- }
- return totalGrades / grades.length;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter student's name: ");
- String name = scanner.nextLine();
- double[] grades = new double[12];
- boolean excluded = false;
- int year = 1;
- while (year <= 12) {
- System.out.print("Enter grade for year " + year + ": ");
- double grade = scanner.nextDouble();
- if (grade < 4) {
- System.out.println(name + " has been excluded at " + year + " grade");
- excluded = true;
- continue;
- }
- grades[year - 1] = grade;
- year++;
- }
- if (!excluded) {
- double averageGrade = calculateAverageGrade(grades);
- System.out.printf("%s graduated. Average grade: %.2f\n", name, averageGrade);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement