Mini Project: Student Grade Calculator
Build a simple Java program that calculates the average mark and displays a grade.
Java Code
Study the example and understand what each part does.
public class Main {
public static void main(String[] args) {
int mathematics = 80;
int science = 75;
int english = 85;
double average =
(mathematics + science + english) / 3.0;
System.out.println(
"Average: " + average
);
if (average >= 70) {
System.out.println("Grade: A");
} else if (average >= 60) {
System.out.println("Grade: B");
} else if (average >= 50) {
System.out.println("Grade: C");
} else {
System.out.println("Grade: D");
}
}
}
Java code normally runs using the Java Development Kit on a computer, Android Studio or another Java development environment. This course page presents the code examples without pretending that the browser is running Java directly.
Expected Output / Result
Average: 80.0 Grade: A
Finished this lesson?
Mark it complete to update your course progress.