Java Program to find the average of 5 subjects

In this program, You will learn how to find an average of 5 subjects in Java.

int sum = a + b + c + d + e;

int avg = sum / 5;

Example: How to find the average of 5 subjects in java.

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        float a, b, c, d, e, sum, avg;

        Scanner sc = new Scanner(;
        System.out.print("Enter five subject marks:");

        a = sc.nextFloat();
        b = sc.nextFloat();
        c = sc.nextFloat();
        d = sc.nextFloat();
        e = sc.nextFloat();

        sum = a + b + c + d + e;
        avg = sum / 5;

        System.out.println("Sum of all subjects:" + sum);
        System.out.println("Average of subjects:" + avg);



Enter five subject marks:10 20 30 40 50
Sum of all subjects:150.0
Average of subjects:30.0

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.