Skip to main content

Step-by-step tutorial

Java Tutorial: Build a Student Grade Calculator

Create a small console program that reads marks, calculates an average, and prints Pass or Needs practice with clean methods.

Javabeginner4 min readProgramming languages

Learning overview

Estimated time
4 minutes
Difficulty
Beginner
Prerequisites
No prior experience required
Learning outcome
Explain java using a clear mental model · Apply java in practical Java work
Last updated
July 18, 2026

What you will build and learn

You will build a StudentGradeApp that stores three scores, computes an average, and prints a result message. Keep calculation separate from printing so each part stays testable.

  • Use a class with a main method
  • Store scores in variables or an array
  • Write a method that returns the average
  • Use if/else for the pass decision

Step 1: Create the program skeleton

Every beginner Java program needs a class and a main method. main is the starting door when you press Run.

StudentGradeApp.java
public class StudentGradeApp {
  public static void main(String[] args) {
    System.out.println("Grade calculator ready");
  }
}

Output

Grade calculator ready

Step 2: Calculate the average in a method

Methods package reusable steps. Returning a value keeps math separate from display.

average method
public static double average(int a, int b, int c) {
  return (a + b + c) / 3.0;
}

Step 3: Decide Pass or Needs practice

After you have an average, use if/else to choose a message. Then extend the project with more subjects or letter grades.

Frequently asked questions

Why divide by 3.0 instead of 3?

Using 3.0 keeps the result as a decimal average. Dividing only ints can truncate the fractional part.

Where should beginners place main?

Inside a public class that matches the file name, as public static void main(String[] args).

Topic graph

A taxonomy-generated path through this subject.

  1. Java
  2. Programming languages
  3. java
  4. tutorial
  5. methods
  6. beginners
  7. What Is Java in Programming?
  8. Learn Java: From First Program to Real Applications
  9. C Tutorial: Build a Student Grade Calculator

Recommended automatically from shared technologies, topics, intent, and difficulty.

Hand-picked companion pages that deepen this topic.

Your next steps

Continue learning

  1. 1glossaryWhat Is Java in Programming?
  2. 2guidesLearn Java: From First Program to Real Applications
  3. 3guidesC Tutorial: Build a Student Grade Calculator
  4. 4guidesC++ (Cpp) Tutorial: Build a Student Grade Calculator